indique/elm-pairdict/4.0.2

NOTE: the latest version is 6.0.3

Pair

type alias Pair left right =
( left, right )

( left, right ) as a value-pair.

openClosedCurlyBracePair=
  ( '{', '}' )

create

decode : Decoder left -> Decoder right -> Decoder (Pair left right)

A Json.Decode.Decoder for Pairs, encoded by encodePair

"""
{
 \"left\": 1,
 \"right\": 11
}
"""
|>Decode.decodeString
    (Pair.decode Decode.int Decode.int)

Ok ( 1, 11 )

or through the constructor

access

leftIn : Pair left right -> left

access the left value in a Pair.

openClosedCurlyBracePair=
  ( '{', '}' )
openCurly= leftIn openClosedCurlyBracePair
rightIn : Pair left right -> right

access the right value in a Pair.

openClosedCurlyBracePair=
  ( '{', '}' )
closedCurly= right openClosedCurlyBracePair

shape

mapLeft : (left -> resultLeft) -> Pair left right -> Pair resultLeft right

map the left value in a Pair

( 128522, "smile" )
|>mapLeft Char.fromCode

( '😊', "smile" )

This is handy when using maps or folds etc.

namedEmojiCodes=
  PairDict.empty
  |>PairDict.insert ( 127824, "pear" )
  |>PairDict.insert ( 127795, "tree" )
namedEmojis=
  namedEmojiCodes
  |>PairDict.map (Pair.mapLeft String.fromInt)

PairDict.fromList [ ( '🍐', "pear" ), ( '🌳', "tree" ) ]

mapRight : (right -> resultRight) -> Pair left right -> Pair left resultRight

map the right value in a Pair

( "smile", 128522 )
|>mapRight Char.fromCode

( "smile", '😊' )

This is handy when using maps or folds etc.

namedEmojiCodes=
  PairDict.empty
  |>PairDict.insert ( "pear", 127824 )
  |>PairDict.insert ( "tree", 127795 )
namedEmojis=
  namedEmojiCodes
  |>PairDict.map (Pair.mapLeft String.fromInt)

PairDict.fromList [ ( "pear", '🍐' ), ( "tree", '🌳' ) ]

encode : (left -> Value) -> (right -> Value) -> Pair left right -> Value

Convert a Pair to a Json.Encode.Value.

Encode.encode 1
  (Pair.encode
    Encode.int Encode.int
    ( 1, 11 )
  )


"""
{
 \"left\": 1,
 \"right\": 11
}
"""