You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On its own this function seems to do so little that it's not worth adding. But I see the use case there, and I wonder if it could be addressed more directly, with something like
if : (() -> a) -> Bool -> Maybe a
if fn predicate =
if predicate then
Just (fn ())
else
Nothing
True
|> Maybe.Extra.if (\() -> "ok")
-- Just "ok"
(Just a rough sketch, it'd need a different name.)
I have two concerns:
It encourages using booleans and ifs which often mean data models that have invalid states. I've turned down previous feature requests for that reason. That's not a deal breaker; Maybe.Extra is a fine place to put useful but slightly ugly functions (for example, isJust has this problem but definitely belongs here), but I think it requires being more careful that its usefulness will outweigh those problems.
It's not that hard to reimplement when needed, and I'm not sure it'd be a common enough use case to make it worth including here. Can you link to examples in real Elm or Haskell codebases that show people going out of their way to implement this or similar functions on their own, or examples where this or a similar function would be useful?
In general, I like to be skeptical and conservative about what should be included. There could be something good here, but you have to show it'll be good.
In Haskell: https://hackage.haskell.org/package/base-4.15.0.0/docs/Control-Monad.html#v:guard
This is is used to short-circuit Maybe computations based on a condition:
The text was updated successfully, but these errors were encountered: