what's the most straightforward way to get a colle...
# codereview
e
what's the most straightforward way to get a collection out of this
Copy code
for (lib in listOf("gluegen:gluegen-rt", "jogl:jogl-all"))
                for (platform in listOf("linux-aarch64", "linux-amd64", "linux-armv6hf", "linux-i586",
                                        "macosx-universal", "windows-amd64", "windows-i586"))
                    "org.jogamp.$lib-natives-$platform"
I came out with this
Copy code
val libs = listOf("gluegen:gluegen-rt", "jogl:jogl-all")
val platforms = listOf("linux-aarch64", "linux-amd64", "linux-armv6hf", "linux-i586", "macosx-universal", "windows-amd64", "windows-i586")
platforms.flatMap { p -> libs.map { "org.jogamp.$it-natives-$p" } }
k
What you have is probably as good as it gets. You can also create a
cartesianProduct
extension function just like this StackOverflow answer. If your team is more familiar with a procedural style, this way doesn't look too bad either:
Copy code
buildList {
    for (lib in libs)
        for (platform in platforms)
            add("org.jogamp.$lib-natives-$platform")
}
👍 3
e
Copy code
buildList {
    for (lib in libs) {
        platforms.mapTo(this) { platform ->
            "org.jogamp.$lib-natives-$platform"
        }
    }
}
is also an option. fewer temporaries than
.flatMap{.map}
but basically the same
👍 1