take i = isolate i =$ consumeSubject to fusion Since 0.3.0
>>> take 5 "Hello World!" "Hello" >>> take 3 [1,2,3,4,5] [1,2,3] >>> take 3 [1,2] [1,2] >>> take 3 [] [] >>> take (-1) [1,2] [] >>> take 0 [1,2] []It is an instance of the more general genericTake, in which n may be of any integral type.
take 0 = return () take (m + n) = take m >> take n
take <infinity> = cat take (min m n) = take m >-> take n
\(Shape xs) (List ys) -> Match.take xs ys == List.take (length xs) ys
ghci> is <- Streams.fromList [1..9::Int] ghci> is' <- Streams.take 1 is ghci> Streams.read is' Just 1 ghci> Streams.read is' Nothing ghci> Streams.peek is Just 2 ghci> Streams.unRead 11 is' ghci> Streams.peek is Just 11 ghci> Streams.peek is' Just 11 ghci> Streams.read is' Just 11 ghci> Streams.read is' Nothing ghci> Streams.read is Just 2 ghci> Streams.toList is [3,4,5,6,7,8,9]
>>> S.toList $ S.take 3 $ each "with" "wit" :> ()
>>> S.readFile "stream.hs" (S.stdoutLn . S.take 3) import Streaming import qualified Streaming.Prelude as S import Streaming.Prelude (each, next, yield)
take 5 "Hello World!" == "Hello" take 3 [1,2,3,4,5] == [1,2,3] take 3 [1,2] == [1,2] take 3 [] == [] take (-1) [1,2] == [] take 0 [1,2] == []It is an instance of the more general genericTake, in which n may be of any integral type.
take n = fromDistinctAscList . take n . toAscList