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 memptyIfTrue/False functions #293

Closed
vrom911 opened this issue May 14, 2020 · 2 comments · Fixed by #295
Closed

Add memptyIfTrue/False functions #293

vrom911 opened this issue May 14, 2020 · 2 comments · Fixed by #295
Assignees
Labels
enhancement New feature or request new Bring something new into library (add function or type or interface)

Comments

@vrom911
Copy link
Member

vrom911 commented May 14, 2020

memptyIfFalse should return mempty when the given predicate is unsatisfied (False), otherwise, return the default given value:

memptyIfFalse :: Monoid m => Bool -> m -> m
@vrom911 vrom911 added enhancement New feature or request new Bring something new into library (add function or type or interface) labels May 14, 2020
@vrom911 vrom911 added this to the v0.7.0.0: Refiner milestone May 14, 2020
@vrom911 vrom911 self-assigned this May 14, 2020
vrom911 added a commit that referenced this issue May 14, 2020
chshersh pushed a commit that referenced this issue May 14, 2020
@srid
Copy link

srid commented May 24, 2020

Would this be a good addition?

memptyIfFalseM :: (Monad m, Monoid a) => m Bool -> m a -> m a

EDIT: What I meant to ask for was:

-- Current
whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()
-- New one
memptyIfNothingM :: (Monad m, Monoid a) => m (Maybe a) -> (a -> m a) -> m a

@chshersh
Copy link
Contributor

@srid That sounds like an interesting proposal 🙂 I don't mind adding new combinators to relude, since at least the names don't conflict with anything. However, when adding new functions, we need to consider multiple things, so I encourage you to open a separate issue to discuss new functions, possible names and types, and especially use-cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new Bring something new into library (add function or type or interface)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants