Module

Codec.Decoder

Package
purescript-json-codecs
Repository
jordanmartinez/purescript-json-codecs

#DecoderFn Source

newtype DecoderFn path handlers e extra from to

Think of this as

forall e
  . Semigroup e
 => { path :: path         -- current 'path' in `from` value (e.g. Json)
    , handlers :: handlers -- handlers for building custom error
    , extra :: extra       -- a slot for any extra goodies (e.g. "local" type class instances)
    }
 -> from                   -- value being decoded
 -> V e to                 -- monad that 
                           --  1. fails with accumulated error using `<>`, or
                           --  2. succeeds with `to` value

but where

  • the from -> V e to function has been converted to an uncurried function: Fn1 from (V e to)
  • each of the record's labels has been spread into "slots" in an uncurried function Fn1 from (V e to) -> Fn4 path handler extra from (V e to)
  • and the Semigroup's append/<> has been inlined to reduce type class dictionary overhead Fn4 path handler extra from (V e to) -> Fn5 path appendFn handler extra from (V e to)

Constructors

Instances

#getPath Source

getPath :: forall path handlers e extra from. DecoderFn path handlers e extra from path

#getInput Source

getInput :: forall path handlers e extra from. DecoderFn path handlers e extra from from

#altAccumulate Source

altAccumulate :: forall path handlers e extra from a. DecoderFn path handlers e extra from a -> DecoderFn path handlers e extra from a -> DecoderFn path handlers e extra from a

Works like alt/<|>. Decodes using the first decoder and, if that fails, decodes using the second decoder. Errors from both decoders accumulate.

#altLast Source

altLast :: forall path handlers e extra from a. DecoderFn path handlers e extra from a -> DecoderFn path handlers e extra from a -> DecoderFn path handlers e extra from a

Same as altAccumulate except only the last error is kept. Helpful in cases where one is decoding a sum type with a large number of data constructors.