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
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)]]]
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.