Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 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
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.
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