NonEmpty version of `span`
stkb opened this issue · 1 comments
Although a little unwieldy, the NonEmpty version of span should really have a signature like this, to preserve the non-emptyness (the current version loses it):
span :: forall a.
(a -> Boolean) ->
NonEmptyList a ->
Either { init :: List a, rest :: NonEmptyList a } { init :: NonEmptyList a, rest :: List a }Or maybe it should be a new function?
Edit: Just realized it's probably just as easy to check whether init is empty and use the original list instead of rest in that case. I'll leave this here anyway
I think for most functions in this library, there are going to be a few options for the nonempty variants, with various ergonomics/safety tradeoffs, so it's not necessarily clear that it should have a signature like that as opposed to the one it has currently. Also, even if we were to add this as a new function, there's a cost in that it makes the API larger and therefore requires more work to get your head around completely, and adds risk for future maintenance (e.g. if we add this and then end up deciding we want to change it again later). Sorry to be annoying, but I think adding functions to the core libraries needs a more thorough justification, with examples, at this point in the language's development.