47degrees / case-classy

configuration with less hassle
http://47deg.github.io/case-classy/
Apache License 2.0
68 stars 8 forks source link

Decoder creation from Try #64

Open andyscott opened 7 years ago

andyscott commented 7 years ago

It would be useful to be able to create decoders directly from A => Try[B]. The error can be directly turned into the underlying error wrapper.

For example, for monix-kafka:

implicit val decodeKafkaProducerConfig: ConfigDecoder[KafkaProducerConfig] =
    Decoder.instance(c => Try(KafkaProducerConfig(c)).toEither.leftMap(DecodeError.Underlying(_)))  

this ideally could just be written as:

implicit val decodeKafkaProducerConfig: ConfigDecoder[KafkaProducerConfig] =
    Decoder.instance(c => Try(KafkaProducerConfig(c)))