What is the shortest & safest way to add items...
# getting-started
r
What is the shortest & safest way to add items from a subList to another list?
Copy code
srcList.subList(from, to).mapTo(destList) { convert(it) }
subList
may throw IndexOutOfBound, doesn't it?
d
Not sure what you are trying to achieve, do you want
to
and
from
to be constrained to the list's size automatically if they are too large?
r
I just want to make the above line more concise without raising IndexOutOfBoundException
d
What do you want to happen in case the indices are out of bounds though?
r
swallow the exception
d
Yes, but what should the value of the expression be?
r
keep
from
, minimize
to
d
And if
from
is out of bounds? 😄
r
ok, let me change it to
srcList.take(count)
d
take
never throws 😉
🍺 1
r
nice, let me check 👍