given a list [a, b, c, d], what is the idiomatic w...
# stdlib
r
given a list [a, b, c, d], what is the idiomatic way to split it into two parts at a given index? Using subList feels clunky. I would like to write list.splitAt(2) to get [[a, b], [c, d]
d
You could argue that this is "more idiomatic", but
subList
is definitely more efficient: https://pl.kotl.in/9Dp69Ywze
And I don't think
subList
is very "clunky": https://pl.kotl.in/lKg9jC091
Not also that
subList
is a view of the underlying list (i.e. it will reflect changes in the underlying list), whereas
take
and
drop
are copying
r
I made an off-by-one bug with subList which I just now corrected