Packages

Bootstrapped algebraic data types for Elixir, forked by doma for maintenance and testing packagesets

Current section

Files

Jump to
doma_algae lib algae tree binary_search apply.ex
Raw

lib/algae/tree/binary_search/apply.ex

alias Algae.Tree.BinarySearch.{Empty, Node}
import TypeClass
use Witchcraft
definst Witchcraft.Apply, for: Algae.Tree.BinarySearch.Empty do
def convey(_, _), do: %Empty{}
end
definst Witchcraft.Apply, for: Algae.Tree.BinarySearch.Node do
def convey(_, %Empty{}), do: %Empty{}
def convey(%{node: node, left: left, right: right}, tree_funs = %Node{node: fun}) do
%Node{
node: fun.(node),
left: Witchcraft.Apply.convey(left, tree_funs),
right: Witchcraft.Apply.convey(right, tree_funs)
}
end
end