indique/elm-pairdict/2.2.0

NOTE: the latest version is 6.0.3

Pair

type alias Pair left right =
{ left : left
, right : right
}

left & right as a value-pair To create, use

{ left= {-leftValue-}, right= {-rightValue-} }

access through

partners= { left= "light blue", right= "lightBlue" }
leftValue= .left pair
rightValue= .right pair

create

through the constructor

{ left= {-leftValue-}, right= {-rightValue-} }

or @docs decode

access

through .left & .right

shape

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

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" ) ]

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

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", '🌳' ) ]

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
    { left= 1, right= 11 }
  )


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