/// <summary> /// Map the input of the decoder. /// </summary> public static Decoder <TRaw2, T> Contramap <TRaw1, T, TRaw2>( this Decoder <TRaw1, T> decoder, [NotNull] Func <TRaw2, TRaw1> f) { return(decoder.Dimap(f, x => x)); }
/// <summary> /// Project the elements of the tuple in the result to the /// arguments of the given function. /// </summary> public static Decoder <TRaw, T> Construct <TRaw, T1, T2, T>( this Decoder <TRaw, Pair <T1, T2> > decoder, [NotNull] Func <T1, T2, T> f) { return(decoder.Map(t => f(t._1, t._2))); }
/// <summary> /// Map the output of the decoder. /// </summary> public static Decoder <TRaw, T2> Map <TRaw, T1, T2>( this Decoder <TRaw, T1> decoder, [NotNull] Func <T1, T2> f) { return(decoder.Dimap <TRaw, T1, TRaw, T2>(x => x, f)); }
/// <summary> /// Create a Decoder that will select the first succesful result, or /// the last failure. /// </summary> public static Decoder <TRaw, T> Or <TRaw, T>( this Decoder <TRaw, T> decoder1, Decoder <TRaw, T> decoder2) { return(new Decoder <TRaw, T>((id, x) => decoder1.Run(id, x) || decoder2.Run(id, x))); }