Cindiary/elm-not-empty/1.0.0

NOTE: the latest version is 1.2.0

Json.Decode.NotEmpty

Functions for encoding not empty collections into JSON values

list : Decoder item -> Decoder (List item)

Decode a JSON array into a NotEmpty.List

decodeString ( list int ) "[ 1, 2, 3 ]"   == Ok ( NotEmpty.List.withHead 1 [ 2, 3 ] )
decodeString ( list bool ) "[]"           == Err ...
array : Decoder item -> Decoder (Array item)

Decode a JSON array into a NotEmpty.Array

set : Decoder comparable -> Decoder (Set comparable)

Decode a JSON array into a NotEmpty.Set.Set

dict : Decoder value -> Decoder (Dict String value)

Decode a JSON object into a NotEmpty.Dict

import Json.Decode as D
import Json.Decode.NotEmpty exposing(dict)


D.decodeString ( dict D.int ) "{ \"alice\": 42, \"bob\": 99 }" == Ok ( NotEmpty.Dict.fromListWithPair "alice" 42 [ ( "bob", 99 ) ] )


D.decodeString ( dict D.int ) "{}" == Err ...