-
Notifications
You must be signed in to change notification settings - Fork 102
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
Should Monoid(undefined)
return the empty Monoid?
#301
Comments
So this is a valid construction. It has to do with what is called a So the solution you have is the correct one, math-wise, except you could clean it up by using safeLift like: // isNonEmptyArray :: a -> Boolean
const isNonEmptyArray =
and(isArray, not(isEmpty))
// isAllExclusive :: a -> Maybe Boolean
const isAllExclusive = safeLift(
isNonEmptyArray
mreduceMap(All, isExclusive),
) Personally I would keep it in a |
Okay. So other than those laws on why undefined maps to empty. const { isArray, isEmpty, } = require('crocks')
// isACat :: a -> Boolean
const isACat =
x => !!(x && x.type === 'cat')
// allCats :: a -> Boolean
const allCats = xs =>
isArray(xs) && !isEmpty(xs)
? xs.reduce((acc, x) => acc && isACat(x), true)
: false
log(
allCats([])
) Noice if you remove the check in |
Now you could go the Semigroup route, with |
@evilsoft Do we want to close this? it feels like it's complete |
@dalefrancis88 Been giving this a lot of thought and after careful 🌽sideration, I am 💯 on board with what @bennypowers is saying. I am thinking that this behavior of In the case of Thoughts? |
Sounds good. I'll create a new issue with the details of what needs to be done and reference and collar this issue |
Closing as this issue has a resolution and the work will be tracked #371 |
Observe:
Should monoid constructors return the empty monoid when called with
nil
?A practical implication:
Users could reasonably expect
allExclusive([])
to be false, since the array has no 'exclusive' members.In this case, developers will have to do the following, which strikes me as burdensome:
The text was updated successfully, but these errors were encountered: