Skip to content

Conversation

Prillan
Copy link

@Prillan Prillan commented May 3, 2024

I was quite surprised to find that there were no scanLeft on any of the non-empty collections. Furthermore, the tail of a scan on a non-empty collection is itself non-empty, which might be a useful property to expose. The name scanLeftTail was the best I could come up with for now and it's of course open to bike-shedding.

Putting out this PR as a draft to get some input on it. Will add tests and documentation if you all consider it useful!

val nel = NonEmptyList.of(1, 2, 3)
val f: (Int, Int) => Int = ???
// Before
nel.toList.scanLeftNel(0)(f)
// After
nel.scanLeft(0)(f)

// And, before
nel.tail.scanLeftNel(f(0, nel.head))(f)
// After
nel.scanLeftTail(0)(f)

The others (NonEmptyChain, etc.) don't have the scanLeftNel syntax and requires more work to get the same result.

Finally, the implementations in this draft are a bit mixed. Don't worry about that for now. Again, I'm mostly checking if people would find this useful or not.

Prillan added 2 commits May 3, 2024 15:50
Considering doing a scan on a non-empty collection yields a collection
with at least _two_ elements, this method helps users discover that
fact.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant