how do i use `mapto` plus `takeif` in chain, so th...
# announcements
s
how do i use
mapto
plus
takeif
in chain, so that only those which satisfy operation are mapped to an arraylist?
w
You want to take only certain items from the collection, map them to other object, and put everything in an array list? In that case I think it’d be
collection.filter { }.mapTo(arrayList()) { }
t
Copy code
collection.mapNotNullTo(arrayListOf()) { item ->
    item.transform().takeIf { it.satisfiesPredicate() }
}
g
Yes, Thibault was faster 🙂 mapNotNullTo is the way to do that, but only for non-nullable values