These are chat archives for fthomas/refined

4th
Dec 2017
Peter Mortier
@kwark
Dec 04 2017 05:49
@fthomas I have noticed that using infix type notation for predicates does not seem to work, example scastie: https://scastie.scala-lang.org/kwark/0v3U5OtSSlCypBxeCJoLrA Is this a known issue? or am I just doing something wrong?
Frank S. Thomas
@fthomas
Dec 04 2017 07:50
@kwark Try to use parens: String Refined (NonEmpty And MaxSize[W.`256`.T])? Maybe the compiler interprets your version as And[Refined[String, NonEmpty], MaxSize].
Peter Mortier
@kwark
Dec 04 2017 08:46
@fthomas thanks, works like a charm!
Lance Walton
@lancewalton
Dec 04 2017 10:55

Hi all. I have:

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

object EmailAddress {
  type EmailAddressRefinementType = MatchesRegex[W.`.+@.+`]
  type EmailAddress               = String Refined EmailAddressRefinementType

  def unapply(s: String): Option[EmailAddress] = apply(s)

  def apply(s: String): Option[EmailAddress] = refine(s).toOption

  def refine(s: String): Either[String, EmailAddress] = refineV[EmailAddressRefinementType](s)
}

& I'm getting a compilation error at the refine method:

[error] <Redacted like a Brexit impact report>/EmailAddress.scala:16:92: could not find implicit value for parameter v: eu.timepit.refined.api.Validate[String,<Redacted like a Brexit impact report>.EmailAddress.EmailAddressRefinementType]
[error]   def refine(s: String): Either[String, EmailAddress] = refineV[EmailAddressRefinementType](s)

Obviously there is a missing implicit Validate instance. Does one exist somewhere, or do I need to write one myself?

Frank S. Thomas
@fthomas
Dec 04 2017 12:03
@lancewalton The argument to MatchesRegex looks suspicious. It should be W.`".+@.+"`.T. And yes, there is an implicit instance in string._ that should be picked up by the compiler.
Lance Walton
@lancewalton
Dec 04 2017 14:34
@fthomas Doh! Thanks.