Applies the given mappers to data to extract a tuple of parameters for calling the factory. If a mapper returns a JsonAccessError, this function immediately returns it. Example:
mappers
data
factory
JsonAccessError
type Item = { name: string, price: number };const data = ["socks", 3.14]; // assumed result of jsonParseconst item: Maybe<Item> = jsonAsType( data, [jsonStringGetter(0), jsonNumberGetter(1)]), (n, p) => ({ name: n, price: p })); Copy
type Item = { name: string, price: number };const data = ["socks", 3.14]; // assumed result of jsonParseconst item: Maybe<Item> = jsonAsType( data, [jsonStringGetter(0), jsonNumberGetter(1)]), (n, p) => ({ name: n, price: p }));
This gets even simpler if Item is a class and we can use jsonAsInstance.
Item
to pick values from.
is a tupe of functions picking values from data or return a JsonAccessError
must take a parameter list with the parameter types those produces by the mappers.
either a JsonAccessError or the result of calling the factory
Applies the given
mapperstodatato extract a tuple of parameters for calling thefactory. If a mapper returns aJsonAccessError, this function immediately returns it. Example:This gets even simpler if
Itemis a class and we can use jsonAsInstance.