Decoding and Encoding Basics

There are a few types of methods for encoding and decoding documented below, please see the API documentation for decoding and encoding for more details.

Normally when decoding you are required to pass the data and an optional namespace, however some data sources may provide default data, such as from system properties, environment variables or typesafe config. These all extend the trait DecodeFromDefaultSource which includes a set of decode methods which do not require data to be passed.

Advanced Examples

Extruder includes some default implementations for Either and EitherT, as well as being able to implicitly derive typeclasses from cats when you import cats.instances.all._. The example belore shows how this is possible:

import cats.effect.IO
import extruder.cats.effect.EffectValidation
import extruder.core._
import scala.util.Try
import cats.instances.all._

decodeF[IO, String](List("a"), Map("a" -> "b")) // returns IO("b")
decodeF[Try, String](List("a"), Map("a" -> "b")) // returns Try("b")

// Type alias for EffectValidation monad transformer
type EitherTIO[A] = EffectValidation[IO, A]
decodeF[EitherTIO, String](List("a"), Map("a" -> "b")) // returns EitherT[IO, ValidationErrors, String](IO(Right("b")))

Implementing Your Own Target Monads

As mentioned in Concepts, Extruder allows you to specify target monads for your desired return types. Type classes can be created implicitly