Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 04 08:10

    mergify[bot] on master

    Update sbt-scalafmt to 2.4.5 Merge pull request #1045 from s… (compare)

  • Dec 04 08:10
    mergify[bot] closed #1045
  • Dec 04 08:09
    codecov[bot] commented #1045
  • Dec 04 08:08
    codecov[bot] commented #1045
  • Dec 04 08:03
    mergify[bot] labeled #1045
  • Dec 04 08:03
    mergify[bot] assigned #1045
  • Dec 04 08:02
    scala-steward opened #1045
  • Dec 03 08:16

    mergify[bot] on master

    Update scalafmt-core to 3.2.1 Merge pull request #1044 from s… (compare)

  • Dec 03 08:16
    mergify[bot] closed #1044
  • Dec 03 08:16
    codecov[bot] commented #1044
  • Dec 03 08:15
    codecov[bot] commented #1044
  • Dec 03 08:08
    mergify[bot] labeled #1044
  • Dec 03 08:08
    mergify[bot] assigned #1044
  • Dec 03 08:08
    scala-steward opened #1044
  • Dec 02 06:31

    mergify[bot] on master

    Update sbt-github-actions to 0.… Merge pull request #1043 from s… (compare)

  • Dec 02 06:31
    mergify[bot] closed #1043
  • Dec 02 06:31
    codecov[bot] commented #1043
  • Dec 02 06:31
    codecov[bot] commented #1043
  • Dec 02 06:24
    mergify[bot] labeled #1043
  • Dec 02 06:24
    mergify[bot] assigned #1043
Frank Thomas
@fthomas
I experimented a little bit with implementing the refine macro in Scala 3 here: fthomas/refined#921 . It seems to be possible for predicates that are implemented in terms of functions like >, !, ==, etc. that can be evaluated at compile-time but it would break down for more complex predicates like MatchesRegex, Size, etc.
Oron Port
@soronpo
@fthomas did you try using compiletime.ops?
And I also think there is more to add there by PR-ing to dotty with what is required.
Both for refined and singleton-ops.
I haven't had a chance to look at this yet, but once I finish my Phd, I will get on that.
Hopefully during May
Frank Thomas
@fthomas
For that experiment I didn't looked at compiletime.ops since I was only looking at what functions can be called at compile-time on inline values and not types.
Oron Port
@soronpo
But inline values constraint can rely on type constraints
Endre Galaczi
@chiller
Hello, I have a question about refined-scalacheck . I am trying to produce an Arbitrary instance for String Refined Size[Less[20]] but it will not always succeed. I am puzzled by this because it can make one for Int Refined Less[20] so supposedly collection.buildableSizeArbitrary could use that instance to generate valid collection sizes, but I often get negative size values. Am I using the wrong implicits, or is this a bug in the library?
import eu.timepit.refined.api.Refined
import eu.timepit.refined.collection.Size
import eu.timepit.refined.numeric._
import eu.timepit.refined.scalacheck.all.lessArbitrary
import eu.timepit.refined.scalacheck.string.stringSizeArbitrary
import org.scalacheck.Gen

object Example extends App {

  type T1 = String Refined Size[Less[5]]

  case class CC(value: T1)

  println(implicitly(Gen.resultOf(CC.apply _)).sample)
}
Frank Thomas
@fthomas
@chiller If the Arbitrary for Int Refined Less[5] generates a negative value, Gen.buildableOfN cannot generate a value. Try using a predicate that excludes negative values, e.g. String Refined Size[Interval.Closed[0, 5]].
Endre Galaczi
@chiller
Thank you
Pelle Krøgholt
@pellekrogholt

Hi,

I'm using refined to refine a float value that I'm getting from db. I have a similar usage for int that works (tm)... But struggling with Integral[Float] implicit not in scope.

Context

type ValidValue           = Float Refined Divisible[0.25]

case class MyType(value: ValidValue)

  implicit val myTypeGet: Get[MyType] = Get[Float].temap { raw =>
    refineV[Divisible[0.25]](raw).map(MyType(_))
  }

raises error on compile

could not find implicit value for parameter v: eu.timepit.refined.api.Validate[Float, Divisible[0.25]]
    refineV[Divisible[0.25]](raw).map(MyType(_))

any pointers ?

Frank Thomas
@fthomas
Try using a Float literal: 0.25F
Pelle Krøgholt
@pellekrogholt
Thx for your pointer - I tried with ^^ same error :thought_balloon:
Pelle Krøgholt
@pellekrogholt

@fthomas / others - I still struggle with floats and refined.

To make my struggle more complete I have left out the doobie part

import eu.timepit.refined.api.Refined
import eu.timepit.refined.numeric.Divisible
import eu.timepit.refined.{refineMV}

object RefinedFloatApp extends App {

  type TRefinement = Divisible[0.25f]
  type ValidT      = Float Refined TRefinement

  case class MyType(value: ValidT)

  val myType = MyType(refineMV[TRefinement](0.5f))

  println(s"myType: $myType")

}

raises:

could not find implicit value for parameter v: eu.timepit.refined.api.Validate[Float,RefinedFloatApp.TRefinement]
  val myType = MyType(refineMV[TRefinement](0.f))

when I hover the implicit part through Intellij ide it says:

No implicits found for parameter it: Integral[Float]

and I'm not sure how to get that in scope ?

Frank Thomas
@fthomas
@pellekrogholt It seems that there is just no Integral[Float] instance in Scala's std library
Pelle Krøgholt
@pellekrogholt
@fthomas thx for your feedback . I'm a bit lost here because when I walk down the refined Modulo object I get into scala Integral https://www.scala-lang.org/api/current/scala/math/Integral.html - so naive ? do you know how to get Integral in scope ?
Frank Thomas
@fthomas
@pellekrogholt If it would be defined in the std library, it would be somewhere around here https://github.com/scala/scala/blob/v2.13.5/src/library/scala/math/Numeric.scala#L141. But since the instance does not exists, you have to define it yourself (if that is possible at all).
Pelle Krøgholt
@pellekrogholt
Oki thx for the explanation/pointers ...
javierg1975
@javierg1975

Hi all,
Very new to Refined. So far only trying to run a simple example, but something as simple as this

import eu.timepit.refined.api.Refined
import eu.timepit.refined.string.MatchesRegex
import eu.timepit.refined._

  type Name = String Refined MatchesRegex[W.`"""[A-Z][a-z]+"""`.T]
  case class User(name: Name)

  val daniel = User("Tom")

Will still fail with

error: type mismatch;
        found   : String("Tom")
        required: Name
           (which expands to)  eu.timepit.refined.api.Refined[String,eu.timepit.refined.string.MatchesRegex[String("[A-Z][a-z]+")]]

From the examples I've seen online this should run, but I'm obviously missing something. Maybe an import?
Any hints will be greatly appreciated

Frank Thomas
@fthomas
@javierg1975 Yes, an import is missing. It should work with import eu.timepit.refined.auto._.
1 reply
bblfish
@bblfish:matrix.org
[m]
When I try to load refined with my Scala3 project I get
[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(uri("file:/Volumes/Dev/Programming/Scala3/cosy/"), "root"):
[error]    org.scala-lang.modules:scala-xml _2.13, _3.0.0-RC2
bblfish
@bblfish:matrix.org
[m]

I guess that's related to the build.sbt config line

"org.scala-lang.modules" %% "scala-xml" % "2.0.0-RC1"

where I am on RC2
bblfish
@bblfish:matrix.org
[m]
Ah it works when building from source.
bblfish
@bblfish:matrix.org
[m]
Oops I spoke too early. Same problem.
bblfish
@bblfish:matrix.org
[m]
this fixed it (it seems at least)
("eu.timepit" %% "refined"                 % refinedVersion).exclude("org.scala-lang.modules","scala-xml_2.13")
Beck Gaël
@beckgael

Hi,
Is it possible to include refined import automatically into a custom package object to prevent final user to import both myorga and refined objects.

import myorga._
// and
import eu.timepit.refined._
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._

Is there a way to only do this including refined imports.

import myorga._

Thank you

Drew Boardman
@drewboardman
hey, I'm trying to use the refined.scalacheck.strings package - and I actually need the Gen instance, not the Arbitrary for NonEmptyString. Do you know of a way to get the generator from the arbitrary?
or does that already exist?
I see you're using Gen.nonEmptyBuildableOf, but it's not obvious how to create a Gen[NonEmptyString] from that
Frank Thomas
@fthomas
@drewboardman Arbitrary.arbitrary[NonEmptyString] will give you the underlying Gen[NonEmptyString]
Phil Nadon
@pnadon
Good morning,
I came across a scenario where I would need to convert Refined types back into regular types (to transform into an externally defined model), I looked in the repo, stackoverflow, and a few other areas but couldn't find any answers on how to do this. Would someone be able to point me in the right direction?
Riley Moher
@avatR630
Hello, has anyone come across projects that use refined types to represent time intervals? With before, after, during, overlaps kind of predicates?
Rohan Sircar
@rohan-sircar
Does import eu.timepit.refined.auto._ affect compile times? I just got done refactoring a test class to manually refine values using apply methods and it made no difference.
vonchav
@voonchav_gitlab
Hi, any chance of another Refined release? :) Kinda need Shapeless 2.3.7 (because 2.3.5/2.3.6 made a change in TupleOps and 2.3.7 reverted that). I can see mergify already merged the PR for Shapeless 2.3.7. I'm hoping there will be a new release soon. Thanks.
Jan Paul Erkelens
@jperkelens

hey folks, fairly new to both refined and scalacheck here but im running into an error i cant seem to resolve:

import eu.timepit.refined.auto._
import eu.timepit.refined.types.string._
import eu.timepit.refined.scalacheck.all._
import eu.timepit.refined.scalacheck.any._

object DatasetFieldGenerator {
  import Gen._
  import Arbitrary._

  def genArray = for {
    name <- arbitrary[NonEmptyString]
    desc <- arbitrary[NonEmptyString]
    required <- arbitrary[Option[Boolean]]
    itemType <- arbitrary[DataType]
  } yield ArrayField(name, desc, required, itemType)

throws a diverging implicit expansion for type org.scalacheck.arbitrary[eu.timepit.refined.types.string.nonemptystring] starting with method arbtuple2 in arbitraryattributes but AFAICT my implicits should be in scope any help would be appreciated

Gabriel Volpe
@gvolpe:matrix.org
[m]

Related issue for me too.

import eu.timepit.refined.scalacheck.all._

val foo = arbitrary[String Refined Size[1]]

Yields this error

[error] diverging implicit expansion for type org.scalacheck.Arbitrary[eu.timepit.refined.api.Refined[String,eu.timepit.refined.collection.Size[1]]]
[error] starting with method arbTuple2 in trait ArbitraryArities
[error]   val foo = arbitrary[String Refined Size[1]]
[error]
This compiles though
arbitrary[String Refined MaxSize[1]]
arbitrary[String Refined Size[Interval.Closed[1, 1]]]
Gabriel Volpe
@gvolpe:matrix.org
[m]
@jperkelens: try removing this line import eu.timepit.refined.scalacheck.any._?
Frank Thomas
@fthomas
The predicate Size[1] is ill-typed for refined but not for Scala. Size is a higher-order predicate and takes another predicate as input but 1 is not a predicate. Size[Equal[1]] should work though.
Gabriel Volpe
@gvolpe:matrix.org
[m]
Interesting, thanks @fthomas !
econoraptor
@econoraptor
do you know of any libraries that encode/decode refinement types to/from strings?
*does anyone
Rohan Sircar
@rohan-sircar
@econoraptor you can use circe with the circe-refined integration
@ parser.decode[PosInt]("1") 
res6: Either[io.circe.Error, PosInt] = Right(1)
@ parser.decode[PosInt]("-1") 
res7: Either[io.circe.Error, PosInt] = Left(DecodingFailure(Predicate failed: (-1 > 0)., List()))
Alexandre DUVAL
@KannarFr
Hi, is it possible to write an akka-http PathMatcher that directly matches to Refined item?
Sean Kwak
@cosmir17

Hi I have

  type Sha1Pred       =  String Refined Size[40]

How do I assign a string value?

val a : Sha1Pred = "da39a3ee5e6b4b0d3255bfef95601890afd80709"

(this doesn't compile)

Alexandre DUVAL
@KannarFr
refineV[Sha1Pred]("<string>") which returns an Either.
V means either \ left and / right (IIRC).
Sean Kwak
@cosmir17
@KannarFr It complains that I don't have an implicit value of !I v: Validate[String, Refined[String, Size[Int(40)]]]