Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Oct 18 16:20

    fthomas on master

    Update scala3-library, ... to 3… Regenerate workflow with sbt-gi… Update build.sbt and 2 more (compare)

  • Oct 18 16:20
    fthomas closed #1026
  • Oct 18 16:10
    codecov[bot] commented #1026
  • Oct 18 16:08
    codecov[bot] commented #1026
  • Oct 18 15:58
    fthomas synchronize #1026
  • Oct 18 15:55
    fthomas synchronize #1026
  • Oct 18 12:23
    mergify[bot] assigned #1026
  • Oct 18 12:23
    mergify[bot] labeled #1026
  • Oct 18 12:23
    scala-steward opened #1026
  • 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
Sean Kwak
@KannarFr It complains that I don't have an implicit value of !I v: Validate[String, Refined[String, Size[Int(40)]]]
Alexandre DUVAL
what about RefType.applyRef[Sha1Pred]("<string>")?
Sean Kwak
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
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
@weihsiu the macros haven't been ported to scala 3 yet. There's a github issue on it.
Walter Chang
@rohan-sircar ok, thanks!
Jack Viers
Anybody had success using refined_3 in scala 3 with MatchesRegex?
Jack Viers
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
I've tried with .* and .{given, *} as well.
Jack Viers
Guess the macro portion is completely gone?
Álvaro Castellanos López
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

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(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

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

Thanks :)

1 reply
Enrique Rodríguez

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

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
Omer Levi Hevroni
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
@omerlh_twitter: Refined uses literal types, they are not "hardcoded values". You can use an implicit ValueOf to get extract the Regex.
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
@fthomas Thank you and all the contributors for this project. I am new in scala and the refined library is very useful !
Frank Thomas
Thanks @sebens!

I'm trying to run simple example mentioned above in the chat

object Test extends App {
  import eu.timepit.refined.W
  import eu.timepit.refined.api.Refined
  import eu.timepit.refined.numeric.Interval
  type Weekday = Int Refined Interval.Closed[W.`1`.T, W.`7`.T]



It asks for implicit ev paramter, am I doing anything wrong here ?

Basically I am trying to do this

object Rank {
  import eu.timepit.refined.W
  import eu.timepit.refined.api.Refined
  import eu.timepit.refined.numeric.Interval
  import shapeless.{:+:, CNil, Coproduct}

  type OneToFourteen = Interval.Closed[W.`1`.T, W.`14`.T]
  type RankValue = Int Refined OneToFourteen

  final case class Rank private(value: OneToFourteen)
  final case class Ace private()
  final case class Ten private(value: 10)
  final case class Jack private(value: 11)
  final case class Queen private(value: 12)
  final case class King private(value: 13)

  type RankIdentifier = Ace :+: King :+: Queen :+: Jack :+: Ten :+: Rank :+: CNil

  def apply(rank: Int) = { rank match {
    case 1 | 14 => Coproduct[RankIdentifier](Ace())
    case 10 => Coproduct[RankIdentifier](Ten(10))
    case 11 => Coproduct[RankIdentifier](Jack(11))
    case 12 => Coproduct[RankIdentifier](Queen(12))
    case 13 => Coproduct[RankIdentifier](King(13))
   // case  _=> Coproduct[RankIdentifier](Rank(rank))

object Test extends App {
Gabriel Volpe
1 reply
The mistake was to expect a predicate as a value in the Rank case class (renamed to Default in the Scastie)
And the W is no longer needed, you can use literals as type OneToFourteen = Interval.Closed[1, 14]