We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6e34687 commit a564ac5Copy full SHA for a564ac5
src/Nix/Utils.hs
@@ -326,10 +326,8 @@ traverseM
326
traverseM f x = sequenceA <$> traverse f x
327
328
-- | Apply a function @n@ times to a given value.
329
-iterateN :: Int -> (a -> a) -> (a -> a)
330
-iterateN 0 _ = id
331
-iterateN 1 f = f
332
-iterateN n f = f . iterateN (pred n) f
+iterateN :: Int -> (a -> a) -> a -> a
+iterateN n f x = fix ((<*> (0 /=)) . ((bool x . f) .) . (. pred)) $ n -- It is hard to read - yes. It is a single action without recursion - yes.
333
334
-- | Apply Kleisli arrow N times, join 'm's.
335
nestM :: Monad m => Int -> (a -> m a) -> a -> m a
0 commit comments