indique/elm-pairdict/2.0.0

NOTE: the latest version is 6.0.3

PairDict

Lookup value-pairs from the left or the right.

👍 How to PairDict

Example: cased letters

lowerUppercaseLetters=
  empty
  |>insert { left= 'a', right= 'A' }
  |>insert { left= 'b', right= 'B' }
  |>insert { left= 'c', right= 'C' }

upperCase char=
  rightOf char lowerUppercaseLetters

try in the ellie of the example cased letters

Example: periodic table

type Element=
  Hydrogen
  | Helium

type alias ProtonCount= Int

elementProtons=
  empty
  |>insert { left= Hydrogen, right= 1 }
  |>insert { left= Helium, right= 2 }

elementsByProtons=
  dictFromRight elementProtons

Example: brackets

You have pairs that belong together:

brackets=
  fromList
    [ ( '(', ')' )
    , ( '{', '}' )
    ]
typeChar character=
  case leftOf character brackets of
    Just opening->
      String.fromList [ opening, character ]

    Nothing->
      case rightOf character brackets of
        Just closing->
          String.fromList [ character, closing ]

        Nothing->
          String.fromChar character

"Typing (: " ++(typeChar '(') ++". Even }: " ++(typeChar '}')

👎 How not to PairDict

Example: automatic answers

answers=
  fromList
    [ ( "Hi", "Hi there!" )
    , ( "Bye", "Ok, have a nice day and spread some love.")
    , ( "How are you", "I don't have feelings :(" )
    , ( "Are you a robot", "I think the most human answer is 'Haha... yes'" )
    ]

please use a dict where it is more appropriate: Dicts are for one-way access

Example: translation, synonymes...

englishGerman=
  fromList
    [ ( "elm", "Ulme" )
    , ( "git", "Schwachkopf" )
    ]

A right → left and backwards relationship isn't fitting, as left or right can have multiple translations!

Please take a look at elm-bidict