Lean 语言参考

21.2. 控制结构🔗

通常,用 IO 编写的程序使用 与其他 monad 中编写的控制结构相同。 有一个特定的 IO 帮助程序。

🔗opaque
IO.iterate {α β : Type} (a : α) (f : α IO (α β)) : IO β
IO.iterate {α β : Type} (a : α) (f : α IO (α β)) : IO β

Iterates an IO action. Starting with an initial state, the action is applied repeatedly until it returns a final value in Sum.inr. Each time it returns Sum.inl, the returned value is treated as a new state.