Skip to content

Commit

Permalink
X.Prelude: Add takeS
Browse files Browse the repository at this point in the history
  • Loading branch information
slotThe committed Oct 26, 2023
1 parent f654082 commit d668e4c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions XMonad/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module XMonad.Prelude (
Stream(..),
(+~),
cycleS,
takeS,
toList,
fromList,
) where
Expand Down Expand Up @@ -504,3 +505,8 @@ infixr 5 +~
-- | Absorb a non-empty list into an infinite stream.
cycleS :: NonEmpty a -> Stream a
cycleS (x :| xs) = s where s = x :~ xs +~ s

-- | @takeS n stream@ returns the first @n@ elements of @stream@; if @n < 0@,
-- this returns the empty list.
takeS :: Int -> Stream a -> [a]
takeS n = take n . toList

0 comments on commit d668e4c

Please sign in to comment.