```val listA = listOf("A","B","C","D","E","F","G",...
# getting-started
d
Copy code
val listA = listOf("A","B","C","D","E","F","G","H","I","J","K","L")
val listB = listOf("C","E","H","K")
I would like to run the function
myfunc(String)
on all elements of listA that are not on listB. What is the most idiomatic way in Kotlin to achieve that?
l
One way you could do it:
Copy code
listA.filter { it !in listB }.forEach(::myfunc)
Or
map(::myfunc)
instead of
forEach
, depends on whether you want to store whatever
myfunc
outputs in a new list.
👏 1
d
many thanks!
s
(listA - listB).forEach(::myfunc)
works for what I believe you’re asking for as well I believe
👏 3
1
d
great @Saharath Kleips!!!
l
Oh, sweet! I didn't know Collections used the
minus()
operator function.
💯 1