Add lefts and rights functions
#71
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the change
Add a
leftsfunction similar to the one existing in Haskell Data.Either.Add also its "partner"
rightsfunction.Motivation
I find
leftsuseful 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
ArrayandList, I've made the type signature more general than the Haskell one (which is only for native Haskell lists).I've used
Monad(andMonoid) to avoid introducing new dependencies. However, it seems to me thatFoldablewould be a better fit thanMonadconceptually. 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