Skip to content

Library enhancement request: Data.Maybe.justIf

Hi,

I found myself often writing the idiom "if a then Just v else Nothing". It can be nicely abbreviated by the function:

justIf :: a -> Bool -> Just a
justIf x True = Just x
justIf x False = Nothing

Which would allow me to write the nicely write- and readable v justIf a.

Asking on #haskell, I got positive feedback about this addition:

<endojelly> nomeata, I'm all for it. my last project was *full* of that idiom
Trac metadata
Trac field Value
Version 6.10.4
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information