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

Add 'maybeToMonoid'? #52

Closed
chshersh opened this issue Jul 5, 2017 · 3 comments
Closed

Add 'maybeToMonoid'? #52

chshersh opened this issue Jul 5, 2017 · 3 comments

Comments

@chshersh
Copy link
Contributor

chshersh commented Jul 5, 2017

I propose to add next function:

maybeToMonoid :: Monoid m => Maybe m -> m
maybeToMonoid = maybe mempty id

When there was Foldable for Maybe, maybeToMonoid is just fold. But I think that this function is useful. And it's behavior and type is clear from name, also what it does and how also clear from type.

@gromakovsky
Copy link
Member

Btw, maybe a id is fromMaybe a.

@chshersh
Copy link
Contributor Author

chshersh commented Jul 5, 2017

@gromakovsky Even better :)

chshersh added a commit that referenced this issue Jul 6, 2017
@chshersh
Copy link
Contributor Author

chshersh commented Aug 4, 2017

One more convenient function is maybeWithMonoid :: Monoid m => Maybe a -> (a -> m) -> m. After it maybeToMonoid x becomes just maybeWithMonoid x id.

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

No branches or pull requests

2 participants