Module for array specific helpers.
Given a funcion fn : Json -> Maybe a maps
a json array, removes Nothings and returns a list.
If the json value is not an array returns an empty list.
inc : Json -> Maybe Float
inc json =
case json of
Number n ->
Just (n + 1)
_ ->
Nothing
json : Json
json =
Array [ Number 0, Number 1, Bool True ]
filterMap inc json == [ 1, 2 ]Wraps a list of strings in a json value.
ofString [ "hello", "world" ]
== Array [ String "hello", String "world" ]Wraps a list of floats in a json value.
ofFloat [ 3.14, 2.718 ]
== Array [ Number 3.14, Number 2.718 ]Wraps a list of ints in a json value.
ofInt [ 3, 4 ]
== Array [ Number 3, Number 4 ]
Maps json arrays. Returns an empty list if json value is not an array.