Comment on Give me Options or give me death
anton@lemmy.blahaj.zone 8 months agoYou can’t random-access an iterator and use it again later.
If your specific use case really needs random access to a list while lazy computing the elements just wrap them in Lazy
and put them in a vector.
Can Rust compute the value of calling a function an infinite number of times?
The return type of an infinitely recursive function / infinite loops is ⊥, a type that by definition has no values. (Known in rust as !
)
PoolloverNathan@programming.dev 8 months ago
Haskell lets you infinitely recurse while still completing in finite time, and there’s even a function (
fix
) for that. Doing e.g.fix (+ 2)
would be an infinite loop if evaluated, yes, butfix (2 :)
would give you a useful value that’s an infinite stream of 2s. (it’s also useful for other things too)