case-classy icon indicating copy to clipboard operation
case-classy copied to clipboard

Decoder creation from Try

Open andyscott opened this issue 7 years ago • 0 comments

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

andyscott avatar Jul 07 '17 21:07 andyscott