Skip to content

Either issues #77

@AHBruns

Description

@AHBruns

Currently, the way Either is implement, there is no way to unwrap it while handling the left value other than a raw case statement. There's no way to fold both the left and right into a single value because the foldable instances are:

definst Witchcraft.Foldable, for: Algae.Either.Left do
  def right_fold(_, seed, _), do: seed
end

definst Witchcraft.Foldable, for: Algae.Either.Right do
  def right_fold(%Right{right: inner}, seed, fun), do: fun.(inner, seed)
end

Ideally we'd implement bifoldable in Witchcraft to allow:

Either.Left.new(1) |> bifold_right(fn err, _ -> {:error, err} end, fn result, _ -> {:ok, result} end)

In the meantime, just making Either a comonad and have it raise when your extract a left will be very helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions