Consider adding `converge` and friends.

Bardur Arantsson spam at scientician.net
Fri Aug 21 07:29:35 UTC 2020


On 20/08/2020 18.36, Ignat Insarov wrote:
> Hello…
> 
> This function first appeared _(to my knowledge)_ in [a Stack Overflow
> answer][1]. I found it useful several times, and eventually [I extended it to a
> family of 4 derived functions][2]: `converge`, `convergeBy`, `fixp` and
> `fixpBy`.
> 
> * `convergeBy` is like `takeWhile` but with a binary predicate.
> * `converge` cuts a list at a point where it starts to repeat itself.
> * `fixp` takes the last element.
> 

FWIW, I've had occasion to have to implement both converge and
convergeBy (albeit in Scala), albeit very rarely.

My case was one of post-processing a linear list of 'instructions' to
remove useless ones -- e.g. adjacement push-pop, etc. Easier to do just
do it be repeated application than trying to figure out how to do it in
a single pass.

+½ from me, I guess :)



More information about the Libraries mailing list