include "Prelude" @inline iterN :: (Integer -> b) -> Integer -> () iterN f n = loop 0 where loop i = if i==n then () else do { f i ; loop (i+1) } @inline anyN :: (Integer -> Boolean) -> Integer -> Boolean anyN f n = loop 0 where loop i = if i==n then False else f i || loop (i+1) @inline allN :: (Integer -> Boolean) -> Integer -> Boolean allN f n = loop 0 where loop i = if i==n then True else f i && loop (i+1) @inline mapFirstN :: (Integer -> Maybe b) -> Integer -> Maybe b mapFirstN f n = loop 0 where loop i = if i==n then Nothing else match f i with r @ (Just _) -> r Nothing -> loop (i+1) @inline concatMapN :: (Integer -> [b]) -> Integer -> [b] concatMapN f n = sum (mapN f n) @inline mapN :: (Integer -> b) -> Integer -> [b] mapN f n = build (\empty cons -> let loop i accum = if i==n then accum else loop (i+1) (cons accum (f i)) in loop 0 empty) @inline filterN :: (Integer -> Boolean) -> Integer -> [Integer] filterN f n = build (\empty cons -> let loop i accum = if i==n then accum else loop (i+1) ( if f i then cons accum i else accum) in loop 0 empty) @inline mapMaybeN :: (Integer -> Maybe b) -> Integer -> [b] mapMaybeN f n = build (\empty cons -> let loop i accum = if i==n then accum else loop (i+1) (match f i with Just v -> cons accum v Nothing -> accum) in loop 0 empty) @inline foldlN :: (a -> Integer -> a) -> a -> Integer -> a foldlN f initial n = loop initial 0 where loop cur i = if i==n then cur else loop (f cur i) (i+1)