I need to create a list of all the `m`’s produced ...
# announcements
d
I need to create a list of all the `m`’s produced by this cartesian product. Is there a nice idiomatic way to do this? Am I missing some kind of built in cartesian product function?
Copy code
messages.forEach { message ->
            recipients.forEach { recipient ->
                val m = messagingService.recordMessage(message, listOf(recipient))
            }
        }
I did this but it feels kind of gross
Untitled
Ah, this is much better but I still feel like it could be better…
m
one solution that comes to mind is to wrap it into
buildList
and just call
add(m)
h
I imagine the best way to handle cartesian product cleanly is to just make a generic method for it. do it the ugly but efficient way and hide it in some other file. ezpz
k
Change the first
map
to a
flatmap
and remove the
flatten
r
I would make something like this. You could also consider making it an extension method on IterableX1
👍 1
e
Replacing
Copy code
Pair(first, second)
with
Copy code
first to second
might be more idiomatic.
👍 1