Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Created September 13, 2016 14:56
Show Gist options
  • Select an option

  • Save ccapndave/73c2a033b9ee1f7aa8c70806d76cd87d to your computer and use it in GitHub Desktop.

Select an option

Save ccapndave/73c2a033b9ee1f7aa8c70806d76cd87d to your computer and use it in GitHub Desktop.
module ListMap exposing
( get
, set
)
import List.Extra exposing (find, dropWhile)
type alias ListMap key value =
List (key, value)
get : key -> ListMap key value -> Maybe value
get key listMap =
listMap
|> find (\(k, _) -> k == key)
|> Maybe.map snd
set : key -> value -> ListMap key value -> ListMap key value
set key value listMap =
listMap
|> dropWhile (\(k, _) -> k == key)
|> (::) (key, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment