Elixir Prelude
Small set of useful utility functions.
Forked to release on Hex.pm, see: https://github.com/houshuang/elixir-prelude/issues/1
Installation
-
Add
elixir_preludeto your list of dependencies inmix.exs:def deps do [{:elixir_prelude, "~> 0.2"}] end
Usage
The most useful utility is provided by Prelude.Map to work with deeply nested Maps or Structs.
defmodule Data do
defstruct data: %{}
end
iex> Prelude.Map.deep_put(%Data{}, [:data, :b, :c, :d], 2)
%Data{data: %{b: %{c: %{d: 2}}}}
iex> Prelude.Map.deep_get(%Data{data: %{b: %{c: %{d: 2}}}}, [:data, :b, :c, :d])
2
iex> Prelude.Map.del_in(%Data{data: %{b: %{c: %{d: 2}}}}, [:data, :b, :c, :d])
%Data{data: %{b: %{c: %{}}}}Other modules:
- Prelude.Atom
- Prelude.List
- Prelude.String
This package has a set of functions that I extracted from projects I worked on (mainly this). Some are very trivial, others (especially in the Prelude.Map module) are more involved. I am mainly putting it together for my own future reuse, but some of it might be useful to others. I would like to add tests, and I will keep adding functions as they come up. Pull requests or suggestions for new functions, better APIs etc are welcome (tests would be awesome).
Stian HÄklev, shaklev@gmail.com, http://reganmian.net
See CHANGELOG.md for progress.