Algebraic Data Types for Elixir: Both functional and fun.
FunLand adds Behaviours to define Algebraic Data Types ('Container' data types) to Elixir, including many helpful operations with them. Where applicable, an ADT implementation for Elixir's built-in types like Lists, Maps, Strings and Functions are included.
Also included are some implementations of commonly-used ADTs, for your leisure. (These might be split off in their own library in the future)
FunLand is based on ideas of the Fantasy Land JavaScript specification for Algebraic Data Types, as well as the implementations of ADTs in other languages, such as Haskell and Idris.
FunLand attempts to use understandable names for the different behaviours and functions, to make ADTs as approachable to newcomers as possible.
As can be seen below in the roadmap, FunLand is not fully finished yet. New pre-release versions might introduce backwards-incompatible changes.
Mostly lacking are:
FunLand.Builtin.*
.Reducable
-> Reducible
. Thank you, Eksperimental!Reducible.to_list/1
overridable so you can add your own implementation for it if you desire.map
over: changing the contents without changing the structure.apply_with
the contents of the second, returning a new strucure.wrap
inside.bind
functions to, which, when given the contents of the structure, return a new version of the structure.combine
them together into one.neutral
value which you can combine something with when you don't have anything else, to keep the result the same.reduce
d to a single value, when given a Combinable (or alternatively, a starting value and a function to combine this with a single value inside the structure).The package is available on hex and can can be specified as a dependency by adding the snippet below in your mix.exs
.
def deps do
[{:fun_land, "~> 0.9.2"}]
end