Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Andy Scott
    @andyscott
    ☺️
    Anthony Garo
    @agaro1121
    @andyscott great job with case classy. Was able to replace my boilerplate in minutes
    BTW we met at Scala Days. I’m Himanhu’s friend LOL
    Raúl Raja Martínez
    @raulraja
    :clap: Awesome!
    Andy Scott
    @andyscott
    @agaro1121 ☺️
    Nice to meet you then!
    ioleo
    @ioleo
    hello in here :) my free monads adventure has now taken me to these coasts :)
    I've been able to quickly replace boilerplate when dealing with simple types
    case class FooConfig(name: String, age: Int)
    Andy Scott
    @andyscott
    👋
    ioleo
    @ioleo
    However for more complicated types like:
    case class Foo(value: String) extends AnyVal
    case class Bar(value: Int) extender AnyVal
    
    case class FooBar(foo: Foo, bar: Bar)
    I had to define a decoder for each AnyVal and join them to then be able to manually create FooBar decoder
    I was hoping classy.generic._ would auto-generate this for me, but it seems it didnt.
    Is there any way to have these also handled automatically?
    ioleo
    @ioleo
    Ok, it seems the wrappers are causing trouble. I guess classy wants to see
    foobar {
      foo.value = "something"
      bar.value = 31
    }
    I guess these wrappers are unnecessary, and for other types I can create simple readers.
     import java.net.URL
     case class Config3(name: String, age: Int, website: URL)
    
      implicit val urlReader = Read.instance { path =>
        ConfigDecoder.instance[URL] { config =>
          Try(new URL(config.getString(path))) match {
            case Success(url) => Right(url)
            case Failure(ex)  => Left(DecodeError.Underlying(ex))
          }
        }
      }
    
      val rawString3 =
        """
          |foo-config {
          |  name = "John"
          |  age = 31
          |  website = "http://www.google.pl"
          |}
        """.stripMargin
    
      val decoder3 = deriveDecoder[Config, Config3].atPath("foo-config")
      println(decoder3(ConfigFactory.parseString(rawString3)))
    ioleo
    @ioleo
    I'm wondering if a utility method on Decoder like this would be accepted?
    import scala.util.{Failure, Success, Try}
    
    // ...
    
    object Decoder {
      def fromMap[A, B](map: A => B): Decoder[A, B] = {
        def run(a: A): Either[DecodeError, B] = Try(map(a)) match {
          case Success(b) => Right(b)
          case Failure(ex) => Left(DecodeError.Underlying(ex))
        }
    
        Instance(run)
      }
      // ...
    }
    ioleo
    @ioleo
    To be used like this: ConfigReader
    Andy Scott
    @andyscott
    @loostro I will give this a look soon. Sorry for the delay.