Skip to content

Conversation

@stackoverflow
Copy link
Contributor

No description provided.

Copy link
Contributor

@HT154 HT154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple questions

stdlib/base.pkl Outdated
/// The looping function returns a [Pair] where the first value is a [Boolean] indicating if the iteration
/// should keep going ([true]) or stop, and the second value is the accumulated result.
/// This function is similar to [fold], but it can short-circuit.
abstract function iterate<Result>(initial: Result, loopFunction: (Result, Element) -> Pair<Boolean, Result>): Result
Copy link
Member

@bioball bioball Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other libraries that also call this iterate?

I also wonder if we should use a clojure-style "return a reduced value" to short-circuit?

In addition to fold, we also have foldBack and reduce. It'd be strange if you can short-circuit here, but not in the other two methods.

Copy link
Contributor Author

@stackoverflow stackoverflow Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good point. I can change the type signature of the folding function to return Element|Reduced<Element> and just change the original functions, instead of creating new ones.

Edit: scratch that. I went with the Clojure approach of having a short-circuiting function that you can call from within any folding/reducing function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants