This commit is contained in:
Gabriel Gonzalez 2015-08-22 13:33:16 -07:00
parent bc52e08f28
commit a4d1d3072d

View file

@ -172,6 +172,7 @@ module Turtle.Prelude (
, sed
, find
, yes
, nl
, limit
, limitWhile
, cache
@ -1010,6 +1011,21 @@ yes = Shell (\(FoldM step begin _) -> do
loop $! x'
loop $! x0 )
-- | Number each element of a `Shell` (starting at 0)
nl :: Num n => Shell a -> Shell (n, a)
nl s = Shell _foldIO'
where
_foldIO' (FoldM step begin done) = _foldIO s (FoldM step' begin' done')
where
step' (x, n) a = do
x' <- step x (n, a)
let n' = n + 1
n' `seq` return (x', n')
begin' = do
x0 <- begin
return (x0, 0)
done' (x, _) = done x
-- | Limit a `Shell` to a fixed number of values
limit :: Int -> Shell a -> Shell a
limit n s = Shell (\(FoldM step begin done) -> do