Copyright | (c) 2021 Kowainik |
---|---|
License | MPL-2.0 |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Stability | Stable |
Portability | Portable |
Safe Haskell | None |
Language | Haskell2010 |
Documentation
maybeToSlist :: Maybe a -> Slist a Source #
slistToMaybe :: Slist a -> Maybe a Source #
Returns Nothing
on an empty list or
where Just
aa
is the first
element of the slist.
Examples
Basic usage:
>>>
slistToMaybe mempty
Nothing
>>>
slistToMaybe (one 42)
Just 42
>>>
slistToMaybe (cons 1 $ cons 2 $ one 3)
Just 1
Laws :
slistToMaybe . maybeToList ≡ id
Reverse is right only on singleton/empty lists
maybeToList . slistToMaybe {empty, singleton slist} ≡ {empty, singleton slist}
Since: 0.2.0.0
mapMaybe :: forall b a. (a -> Maybe b) -> Slist a -> Slist b Source #
The Maybe
version of map
which can throw out elements.
If appliying the given function returns Nothing
, no element is added on to the
result list. If it is
, then Just
bb
is included in the result list.
>>>
maybeEven x = if even x then Just x else Nothing
>>>
s = cons 1 $ cons 2 $ one 3
>>>
mapMaybe maybeEven s
Slist {sList = [2], sSize = Size 1}
If we map the Just
constructor, the entire list should be returned:
>>>
mapMaybe Just s
Slist {sList = [1,2,3], sSize = Size 3}
Since: 0.2.0.0