Packages

FunLand adds Behaviours to define Algebraic Data Types ('Container' data types) to Elixir, such as Functors, Monoids and Monads.

Current section

Files

Jump to
fun_land lib fun_land traversable.ex
Raw

lib/fun_land/traversable.ex

defmodule FunLand.Traversable do
@moduledoc """
TODO: Find out how to use this in a dynamically typed language.
"""
@type traversable(_) :: FunLand.adt
@callback sequence(traversable(a), (a -> FunLand.Applicative.applicative(b))) :: FunLand.Applicative.applicative(traversable(b)) when a: any, b: any
defmacro __using__(_opts) do
quote do
use FunLand.Mappable
use FunLand.Reducable
end
end
def sequence(seq_a, fun) do
do_sequence(seq_a, fun)
end
# Problem: untyped lists. No idea what applicative to wrap with when list is empty. Same for other structures
defp do_sequence(seq_a, _fun) when is_list(seq_a) do
nil
end
end