<@U6ADZLRG9> The hidden Dragon is that the functio...
# functional
r
@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
Agree w/ that assessment; I was following the existing semantics of
.first()
in this case. (My constraints are stdlib atm…)
r
Then the second version generalized to
Iterable<A>
is probably the closest just using the std lib while remaining pure for their immutable impls.
b
đź‘Ť