Skip to content

Commit 185c084

Browse files
authored
Add examples for alt (#58)
1 parent d65c49b commit 185c084

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Control/Alt.purs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ import Data.Semigroup (append)
1818
-- |
1919
-- | For example, the `Array` (`[]`) type is an instance of `Alt`, where
2020
-- | `(<|>)` is defined to be concatenation.
21+
-- |
22+
-- | A common use case is to select the first "valid" item, or, if all items
23+
-- | are "invalid", the last "invalid" item.
24+
-- |
25+
-- | For example:
26+
-- |
27+
-- | ```purescript
28+
-- | import Control.Alt ((<|>))
29+
-- | import Data.Maybe (Maybe(..)
30+
-- | import Data.Either (Either(..))
31+
-- |
32+
-- | Nothing <|> Just 1 <|> Just 2 == Just 1
33+
-- | Left "err" <|> Right 1 <|> Right 2 == Right 1
34+
-- | Left "err 1" <|> Left "err 2" <|> Left "err 3" == Left "err 3"
35+
-- | ```
2136
class Functor f <= Alt f where
2237
alt :: forall a. f a -> f a -> f a
2338

0 commit comments

Comments
 (0)