Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Either issues #77

Open
AHBruns opened this issue Aug 10, 2022 · 1 comment
Open

Either issues #77

AHBruns opened this issue Aug 10, 2022 · 1 comment

Comments

@AHBruns
Copy link

AHBruns commented Aug 10, 2022

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
Copy link

Thank you for submitting an issue! It means a lot that you took the time -- it helps us be better 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant