Skip to content

Commit

Permalink
Add examples for alt (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesfrain authored Oct 13, 2020
1 parent d65c49b commit 185c084
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Control/Alt.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ import Data.Semigroup (append)
-- |
-- | For example, the `Array` (`[]`) type is an instance of `Alt`, where
-- | `(<|>)` is defined to be concatenation.
-- |
-- | A common use case is to select the first "valid" item, or, if all items
-- | are "invalid", the last "invalid" item.
-- |
-- | For example:
-- |
-- | ```purescript
-- | import Control.Alt ((<|>))
-- | import Data.Maybe (Maybe(..)
-- | import Data.Either (Either(..))
-- |
-- | Nothing <|> Just 1 <|> Just 2 == Just 1
-- | Left "err" <|> Right 1 <|> Right 2 == Right 1
-- | Left "err 1" <|> Left "err 2" <|> Left "err 3" == Left "err 3"
-- | ```
class Functor f <= Alt f where
alt :: forall a. f a -> f a -> f a

Expand Down

0 comments on commit 185c084

Please sign in to comment.