From d668e4cb107114ac869a9d814eee77ef7ec9f7e9 Mon Sep 17 00:00:00 2001 From: Tony Zorman Date: Thu, 26 Oct 2023 11:52:40 +0200 Subject: [PATCH] X.Prelude: Add takeS --- XMonad/Prelude.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/XMonad/Prelude.hs b/XMonad/Prelude.hs index d52f49027c..21d0a4f5da 100644 --- a/XMonad/Prelude.hs +++ b/XMonad/Prelude.hs @@ -44,6 +44,7 @@ module XMonad.Prelude ( Stream(..), (+~), cycleS, + takeS, toList, fromList, ) where @@ -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