Uptight.Fold (Uptight v0.2.2-rc)
Foldable plus.
Link to this section Summary
Functions
Folds by gluing the elements. Constraints in typespec are fake and don't do anything except for suggesting required typeclasses.
Inserts glue between each pair of elements. Constraints in typespec are fake and don't do anything except for suggesting required typeclasses.
Link to this section Functions
Link to this function
intercalate(foldable_semigroup, glue)
Specs
intercalate( Witchcraft.Foldable.t() | :and | Witchcraft.Semigroup.t(), Witchcraft.Monoid.t() ) :: Witchcraft.Monoid.t()
Folds by gluing the elements. Constraints in typespec are fake and don't do anything except for suggesting required typeclasses.
Example
iex> Uptight.Result.new(fn -> Uptight.Fold.intercalate([1,2,3], "") end) |> Uptight.Result.is_err?()
true
# iex> Uptight.Fold.intercalate(Witchcraft.Functor.map([1,2,3], &Uptight.Add.new/1), 1)
# 9
iex> Uptight.Fold.intercalate([], 1)
0
iex> Uptight.Fold.intercalate([Uptight.Text.new!("."), Uptight.Text.new!("a.out")], Uptight.Text.new!("/"))
%Uptight.Text{text: "./a.out"}
iex> Uptight.Fold.intercalate([Uptight.Text.new!(".")], Uptight.Text.new!("lol nvm"))
%Uptight.Text{text: "."}
Link to this function
intersperse(foldable_semigroup, glue)
Specs
intersperse( Witchcraft.Foldable.t() | :and | Witchcraft.Semigroup.t(), Witchcraft.Monoid.t() ) :: Witchcraft.Foldable.t() | :and | Witchcraft.Semigroup.t()
Inserts glue between each pair of elements. Constraints in typespec are fake and don't do anything except for suggesting required typeclasses.
Example
iex> Uptight.Fold.intersperse([1,2,3], "the power of elixir")
[1, "the power of elixir", 2, "the power of elixir", 3]
iex> Uptight.Fold.intersperse([Uptight.Text.new!("."), Uptight.Text.new!("a.out")], Uptight.Text.new!("/"))
[%Uptight.Text{text: "."}, %Uptight.Text{text: "/"}, %Uptight.Text{text: "a.out"}]
iex> Uptight.Fold.intersperse([Uptight.Text.new!(".")], Uptight.Text.new!("lol nvm"))
[%Uptight.Text{text: "."}]
Link to this function
right_glued(foldable_semigroup, glue)
Specs
right_glued( Witchcraft.Foldable.t() | :and | Witchcraft.Semigroup.t(), Witchcraft.Monoid.t() ) :: Witchcraft.Foldable.t() | :and | Witchcraft.Semigroup.t()