OrderedCollections (ordered_collections v0.3.0)

OrderedCollections provides sorted data structures for Elixir, including a SortedMap and (eventually) a SortedSet.

Modules

Examples

iex> sm = OrderedCollections.SortedMap.new(%{b: 2, a: 1})
iex> OrderedCollections.SortedMap.get(sm, :a)
1

You can also use convenience functions:

iex> sm = OrderedCollections.new_map(%{x: 10})
iex> sm = OrderedCollections.put_map(sm, :y, 20)
iex> OrderedCollections.get_map(sm, :y)
20

Summary

Functions

Retrieves the value for the given key from a SortedMap, returning a default if the key is missing.

Creates a new empty SortedMap.

Creates a new SortedMap from a regular map.

Inserts a key-value pair into a SortedMap.

Creates a map from a SortedMap.

Functions

get_map(sorted_map, key, default \\ nil)

@spec get_map(OrderedCollections.SortedMap.t(), any(), any()) :: any()

Retrieves the value for the given key from a SortedMap, returning a default if the key is missing.

new_map()

@spec new_map() :: OrderedCollections.SortedMap.t()

Creates a new empty SortedMap.

Examples

iex> sm = OrderedCollections.new_map() iex> OrderedCollections.to_map(sm) %{}

new_map(map)

@spec new_map(map()) :: OrderedCollections.SortedMap.t()

Creates a new SortedMap from a regular map.

Examples

iex> m = %{b: 2, a: 1} iex> sm = OrderedCollections.new_map(m) iex> OrderedCollections.get_map(sm, :a) 1

put_map(sorted_map, key, value)

Inserts a key-value pair into a SortedMap.

to_map(map)

@spec to_map(OrderedCollections.SortedMap.t()) :: map()

Creates a map from a SortedMap.

Examples

iex> sm = OrderedCollections.new_map(%{b: 2, a: 1}) iex> OrderedCollections.to_map(sm) %{a: 1, b: 2}