Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 15 11:43
    etorres starred fthomas/refined
  • Oct 15 08:47
    ghoullier starred fthomas/refined
  • Oct 15 00:51
    faultier starred fthomas/refined
  • Oct 14 14:32
    mergify[bot] closed #1025
  • Oct 14 14:32

    mergify[bot] on master

    Update sbt-ci-release to 1.5.10 Merge pull request #1025 from s… (compare)

  • Oct 14 14:24
    mergify[bot] labeled #1025
  • Oct 14 14:24
    mergify[bot] assigned #1025
  • Oct 14 14:23
    scala-steward opened #1025
  • Oct 13 21:24
    eambrosio starred fthomas/refined
  • Oct 13 02:24
    14sxlin starred fthomas/refined
  • Oct 12 17:54
    b1nd starred fthomas/refined
  • Oct 12 13:41
    thejaminator starred fthomas/refined
  • Oct 11 16:19
  • Oct 11 12:39

    mergify[bot] on master

    Update sbt-scoverage to 1.9.1 Merge pull request #1024 from s… (compare)

  • Oct 11 12:39
    mergify[bot] closed #1024
  • Oct 11 12:39
    codecov[bot] commented #1024
  • Oct 11 12:38
    codecov[bot] commented #1024
  • Oct 11 12:31
    mergify[bot] labeled #1024
  • Oct 11 12:31
    mergify[bot] assigned #1024
  • Oct 11 12:31
    scala-steward opened #1024
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)]]]
Alexandre DUVAL
@KannarFr
what about RefType.applyRef[Sha1Pred]("<string>")?
Sean Kwak
@cosmir17
I got a different message
polymorphic expression cannot be instantiated to expected type;
  Either[String, Refined[String, Size[Int(40)]]]|Refined[String, Size[Int(40)]]
  val a : Sha1Pred = RefType.applyRef[Sha1Pred]("sdf")
I did
val a : Sha1Pred = RefType.applyRef[Sha1Pred]("da39a3ee5e6b4b0d3255bfef95601890afd80709")
Walter Chang
@weihsiu
i am trying to use refined with scala 3. i got as far as declaring types like "NonEmptyString" and "String Refined Contains['@']", but that's about it. importing "eu.timepit.refined.auto.*" doesn't seem to work.
Rohan Sircar
@rohan-sircar
@weihsiu the macros haven't been ported to scala 3 yet. There's a github issue on it.
Walter Chang
@weihsiu
@rohan-sircar ok, thanks!
Jack Viers
@jackcviers
Anybody had success using refined_3 in scala 3 with MatchesRegex?
Jack Viers
@jackcviers
in code that uses the refined type, I can't do val x: MyRefinedType = "example" any more. I have to use ``val x: MyRefinedType = MyRefinedType.unsafeFrom("example") or one of the methods that returnsEither`. Guessing that the value is just not possible to lift to compile time anymore because the macros aren't implemented?
If that's the case, I'll just go back to scala 2.13.6 and await the macro improvements... I use refined quite a bit.
But I didn't find anything in the github issues that indicated that this didn't work any longer, and I thought it was just an implicit def that did this. So what's going on?

Another example:

import eu.timepit.refined.auto._
lazy val x: PosInt = 3

Gives me:

[E007] Type Mismatch Error: <elidedSourceFileLocation>:15:23 -----------------------
[error] 15 |  lazy val x: PosInt = 3
[error]    |                       ^
[error]    |                       Found:    (3 : Int)
[error]    |                       Required: eu.timepit.refined.types.numeric.PosInt
Jack Viers
@jackcviers
I've tried with .* and .{given, *} as well.
Jack Viers
@jackcviers
Guess the macro portion is completely gone?
Álvaro Castellanos López
@AlvaroCaste
Hi :wave: is there a book or so, where to read further about Refined? (apart from The Type Astronaut's Guide to Shapeless Book) Thanks :smile:
Paweł Kołodziejczyk
@lewapek

Hey,
it seems that there is inconsistency between 0.9.25 and 0.9.26 versions of the library
Below you can find minimal code snippet showing that with versions <= 0.9.25 Concrete type could be passed to function which expects Base
With 0.9.26 it's not possible (compilation error)
Is that intentional?

  type BaseRefinement = And[Size[Equal[10]], Forall[LetterOrDigit]]
  type Base = String Refined BaseRefinement

  type ConcreteRefinement = And[StartsWith[W.`"001"`.T], BaseRefinement]
  type Concrete = String Refined ConcreteRefinement

  def funBase(b: Base): Unit = println(b)
  def funConcrete(c: Concrete): Unit = println(c)

  val b: Base = "1234567890"
  val c: Concrete = "0012345678"

  funBase(b)
  funBase(c) // with 0.9.26 doesn't compile, with 0.9.25 works fine

  //    funConcrete(b) // doesn't compile on both versions - that's fine
  funConcrete(c)

Full code snippet ready to compile can be found here (https://gist.github.com/lewapek/3cbf003a000bbe9bf479607e9967d201)

Thanks :)

1 reply
Enrique Rodríguez
@enriquerodbe_twitter

Hi!
Is it possible to use refined to compare two integers that were defined at runtime?
This is what I would want to do:

import eu.timepit.refined._
import eu.timepit.refined.numeric._
import eu.timepit.refined.auto._
import scala.io.StdIn.readInt

for {
    size <- refineV[Positive](readInt())
    index <- refineV[Less[size.type]](readInt())
} yield index

When I try it I get:

could not find implicit value for parameter v: eu.timepit.refined.api.Validate[Int,eu.timepit.refined.numeric.Less[size.type]]

which kind of makes sense, but I wanted to know if I'm missing something or if there's a better way to achieve what I want.

Alexandre DUVAL
@KannarFr

Hi, considering

type AddonCellarID = String Refined StartsWith["cellar_"]
type AddonPulsarID = String Refined StartsWith["pulsar_"]
type AddonID = AddonCellarID Or AddonPulsarID

I'm trying to assign a AddonCellarID in a AddonID field and got

[error] /home/kannar/git/cc/ovd/src/main/scala/com/yo/addon/cellar/actors/AddonCellarAddonActor.scala:132:28: type mismatch;    
[error]  found   : com.yo.global.models.AddonCellarID
[error]     (which expands to)  eu.timepit.refined.api.Refined[String,eu.timepit.refined.string.StartsWith["cellar_"]]                                                                                                                                                            
[error]  required: com.yo.global.models.AddonID                                                                                 
[error]     (which expands to)  eu.timepit.refined.boolean.Or[eu.timepit.refined.api.Refined[String,eu.timepit.refined.string.StartsWith["cellar_"]],eu.timepit.refined.api.Refined[String,eu.timepit.refined.string.StartsWith["pulsar_"]]]                                      
[error]           addon_id = addon.id,                                                                                                   
[error]                            ^

There is a way to do it?

Alexandre DUVAL
@KannarFr
@fthomas
Omer Levi Hevroni
@omerlh_twitter
Hello! A question re refined regex support: I have pretty complex that I used with MatchesRegex, but I would like to re-use the same regex with Pattern to get the groups inside the regex. How can I re-use the regex so I will not have to define it twice? Seems like MatchesRegex supports only hard coded strings
Gabriel Volpe
@gvolpe:matrix.org
[m]
@omerlh_twitter: Refined uses literal types, they are not "hardcoded values". You can use an implicit ValueOf to get extract the Regex.
e.g.
type Rgx = "^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$"
type PersonName = String Refined MatchesRegex[Rgx]

def getRegex(implicit w: ValueOf[Rgx]): Regex = w.value.r
sebens
@sebens
@fthomas Thank you and all the contributors for this project. I am new in scala and the refined library is very useful !