Fxnk v0.1.1 Fxnk.Map View Source
Fxnk.Map
are functions that work with maps.
Link to this section Summary
Link to this section Functions
Specs
Accepts a list of args, returns a curried pick/2
.
Examples
iex> pickArgs = Fxnk.Map.pick([:red, :blue, :orange])
iex> pickArgs.(%{ red: "RED", green: "GREEN", blue: "BLUE", yellow: "YELLOW" })
%{red: "RED", blue: "BLUE"}
Specs
pick/2
takes a Map
and a List
of atoms, and returns a map of only the selected keys that exist. It will
return an empty map if passed an empty map or an empty list.
Examples
iex> Fxnk.Map.pick(%{ red: "RED", green: "GREEN", blue: "BLUE", yellow: "YELLOW" }, [:red, :blue, :orange])
%{red: "RED", blue: "BLUE"}
Specs
Accepts a string key
and returns a function that takes a map
.
Returns the map's value at key
or nil
.
Examples
iex> getProp = Fxnk.Map.prop("foo")
iex> getProp.(%{"foo" => "foo", "bar" => "bar"})
"foo"
iex> getProp2 = Fxnk.Map.prop(:foo)
iex> getProp2.(%{foo: "foo", bar: "bar"})
"foo"
Specs
Accepts a map and a key. Returns the map's value at key
or nil
Examples
iex> Fxnk.Map.prop(%{"foo" => "foo", "bar" => "bar"}, "foo")
"foo"
iex> Fxnk.Map.prop(%{foo: "foo", bar: "bar"}, :foo)
"foo"
Specs
Accepts a list of keys and returns a function that takes a map. Returns a list of the values associated with the keys in the map.
Examples
iex> getProps = Fxnk.Map.props(["foo", "bar"])
iex> getProps.(%{"foo" => "foo", "bar" => "bar", "baz" => "baz"})
["foo", "bar"]
iex> getProps2 = Fxnk.Map.props([:foo, :bar])
iex> getProps2.(%{foo: "foo", bar: "bar", baz: "baz"})
["foo", "bar"]
Specs
Accepts a map and a list of keys and returns a list of the values associated with the keys in the map.
Examples
iex> Fxnk.Map.props(%{"foo" => "foo", "bar" => "bar", "baz" => "baz"}, ["foo", "bar"])
["foo", "bar"]
iex> Fxnk.Map.props(%{foo: "foo", bar: "bar", baz: "baz"}, [:foo, :bar])
["foo", "bar"]