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.
1 parent 4f1882d commit cf33800Copy full SHA for cf33800
src/Data/Maybe.purs
@@ -280,9 +280,23 @@ fromJust (Just x) = x
280
281
-- | One or none.
282
-- |
283
--- | ``` purescript
+-- | ```purescript
284
-- | optional empty = pure Nothing
285
--- | optional (pure x) = pure (Just x)
+-- | ```
286
+-- |
287
+-- | The behaviour of `optional (pure x)` depends on whether the `Alt` instance
288
+-- | satisfy the left catch law (`pure a <|> b = pure a`).
289
290
+-- | `Either e` does:
291
292
293
+-- | optional (Right x) = Right (Just x)
294
295
296
+-- | But `Array` does not:
297
298
299
+-- | optional [x] = [Just x, Nothing]
300
-- | ```
301
optional :: forall f a. Alt f => Applicative f => f a -> f (Maybe a)
302
optional a = map Just a <|> pure Nothing
0 commit comments