Skip to content

Add lefts and rights functions #71

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

l-monnier
Copy link

Description of the change

Add a lefts function similar to the one existing in Haskell Data.Either.
Add also its "partner" rights function.

Motivation

I find lefts useful to collect the error messages of multiple validations of a same value, when such validations do not alter the value. For example, if I want to test that a value is no longer than n, has no forbidden character, contains at least 1 number, etc.

Notes

As in PureScript there are Array and List, I've made the type signature more general than the Haskell one (which is only for native Haskell lists).
I've used Monad (and Monoid) to avoid introducing new dependencies. However, it seems to me that Foldable would be a better fit than Monad conceptually. But I don't think it matters much in practice.

The above makes the documentation a bit tricky as those functions are pretty abstract. I hope it's still understandable while remaining accurate enough.

I let you decide if you want to include those 2 functions in the library.

Checklist

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close [none]
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@natefaubion
Copy link
Contributor

FWIW, functionality like this exists in purescript-filterable.

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

Successfully merging this pull request may close these issues.

2 participants