We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 435566d + 804fc73 commit 6c3cee0Copy full SHA for 6c3cee0
src/Data/Maybe.purs
@@ -2,7 +2,7 @@ module Data.Maybe where
2
3
import Prelude
4
5
-import Control.Alt (class Alt)
+import Control.Alt (class Alt, (<|>))
6
import Control.Alternative (class Alternative)
7
import Control.Extend (class Extend)
8
import Control.MonadZero (class MonadZero)
@@ -269,3 +269,12 @@ isNothing = maybe true (const false)
269
-- | runtime.
270
fromJust :: forall a. Partial => Maybe a -> a
271
fromJust (Just x) = x
272
+
273
+-- | One or none.
274
+-- |
275
+-- | ``` purescript
276
+-- | optional empty = pure Nothing
277
+-- | optional (pure x) = pure (Just x)
278
+-- | ```
279
+optional :: forall f a. Alternative f => f a -> f (Maybe a)
280
+optional a = map Just a <|> pure Nothing
0 commit comments