@benfleis The hidden Dragon is that the function is unsafe and nothing from it's type signature denotes that it's going to blow up if there are no elements. Safe versions of the same functions are:
Copy code
import arrow.data.NonEmptyList
fun <A> NonEmptyList<A>.firstRest(): Pair<A, List<A>> =
head to tail
fun <A> Iterable<A>.firstRest(): Pair<A?, List<A>> =
firstOrNull() to drop(1)
b
benfleis
12/27/2018, 8:24 PM
Agree w/ that assessment; I was following the existing semantics of
.first()
in this case. (My constraints are stdlib atm…)
r
raulraja
12/27/2018, 8:49 PM
Then the second version generalized to
Iterable<A>
is probably the closest just using the std lib while remaining pure for their immutable impls.