Either issues
AHBruns opened this issue · 1 comments
AHBruns commented
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.
github-actions commented
Thank you for submitting an issue! It means a lot that you took the time -- it helps us be better 🙏