Skip to content

Commit 1a2a3b3

Browse files
committed
Add Unfoldable1 for ListT
1 parent 0ee6037 commit 1a2a3b3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Control/Monad/List/Trans.purs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import Data.Maybe (Maybe(..), fromMaybe)
5050
import Data.Newtype (class Newtype)
5151
import Data.Tuple (Tuple(..), fst, snd)
5252
import Data.Unfoldable (class Unfoldable)
53+
import Data.Unfoldable1 (class Unfoldable1)
5354
import Effect.Class (class MonadEffect, liftEffect)
5455

5556
-- | The list monad transformer.
@@ -282,8 +283,17 @@ instance functorListT :: Functor f => Functor (ListT f) where
282283

283284
instance unfoldableListT :: Monad f => Unfoldable (ListT f) where
284285
unfoldr f b = go (f b)
285-
where go Nothing = nil
286-
go (Just (Tuple x y)) = cons (pure x) (defer \_ -> (go (f y)))
286+
where
287+
go = case _ of
288+
Nothing -> nil
289+
Just (Tuple x y) -> cons (pure x) (defer \_ -> (go (f y)))
290+
291+
instance unfoldable1ListT :: Monad f => Unfoldable1 (ListT f) where
292+
unfoldr1 f b = go (f b)
293+
where
294+
go = case _ of
295+
Tuple x Nothing -> singleton x
296+
Tuple x (Just y) -> cons (pure x) (defer \_ -> (go (f y)))
287297

288298
instance applyListT :: Monad f => Apply (ListT f) where
289299
apply = ap

0 commit comments

Comments
 (0)