natpryce
02/07/2023, 10:40 PM(1 .. 10 step 2) returns an IntProgression, ('a' .. 'z' step 2) returns a CharProgression, and there are equivalents for many built in types, but not for user-defined types.
Could the stdlib define the step function for ClosedRange<T>, to return a new stdlib type Progression<T> .?Sam
02/08/2023, 8:01 AMString? Unless it could take a lambda, like generateSequence...Sam
02/08/2023, 9:04 AMinfix fun ClosedRange<String>.step(step: (String) -> String): Iterable<String> =
generateSequence(start, step).takeWhile { it in this }.asIterable()
for (s in "foo".."foooooo" step { it + "o" }) println(s)
I kind of like it! 😄Sam
02/08/2023, 9:04 AMnatpryce
02/08/2023, 12:54 PMnatpryce
02/08/2023, 12:54 PMnatpryce
02/08/2023, 12:55 PM