Is there a simple way to find the index of a particular element in a list?
Essentially, instead of find : (List elem), (elem -> Bool) -> (Result elem [ NotFound ]*)
I'm looking for findIndex : (List elem), (elem -> Bool) -> (Result Nat [ NotFound ]*)
So that it can be used for later operations with get
, set
, replace
, split
etc.
There should be a List.find
, but maybe it hasn't been implemented yet
If it doesn't exist, it could be built with List.walkUntil
Just make the state the current index. Increment it in the looping function. Check the element against a predicate each round. Return the index when an element matches and stop the walk.
Also, probably can get List.findIndex
or something similar added to the standard library, I think it is a common enough use case to merit its own function.
Last updated: Jul 05 2025 at 12:14 UTC