A Json.Decode.Decoder for Pairs, encoded by encodePair
"""
{
\"left\": 1,
\"right\": 11
}
"""
|>Decode.decodeString
(Pair.decode Decode.int Decode.int)
Ok { left= 1, right= 11 }
or through the constructor
map the left value in a Pair
{ left= 128522, right= "smile" }
|>mapLeft Char.fromCode
{ left= '😊', right= "smile" }
This is handy when using maps or folds etc.
namedEmojiCodes=
PairDict.empty
|>PairDict.insert { left= 127824, right= "pear" }
|>PairDict.insert { left= 127795, right= "tree" }
namedEmojis=
namedEmojiCodes
|>PairDict.map (Pair.mapLeft String.fromInt)
PairDict.fromList [ ( '🍐', "pear" ), ( '🌳', "tree" ) ]
map the right value in a Pair
{ left= "smile", right= 128522 }
|>mapRight Char.fromCode
{ left= "smile", right= '😊' }
This is handy when using maps or folds etc.
namedEmojiCodes=
PairDict.empty
|>PairDict.insert { left= "pear", right= 127824 }
|>PairDict.insert { left= "tree", right= 127795 }
namedEmojis=
namedEmojiCodes
|>PairDict.map (Pair.mapLeft String.fromInt)
PairDict.fromList [ ( "pear", '🍐' ), ( "tree", '🌳' ) ]
Convert a Pair to a Json.Encode.Value.
Encode.encode 1
(Pair.encode
Encode.int Encode.int
{ left= 1, right= 11 }
)
"""
{
\"left\": 1,
\"right\": 11
}
"""
left&rightas a value-pair