JetBrains’ Kotlin JVM language appeals to the Java faithful

Kotlin, a high-performance, statically typed “pragmatic language” that leverages the environment of Java Virtual Machine, has reached its official 1.0 release milestone. Created by IDE makers JetBrains, Kotlin — like many other non-Java languages that run on the JVM — is meant to run where Java runs and make use of the existing culture of Java libraries and tooling. Java, in turn, can use items built in Kotlin.
http://www.javaworld.com/article/3033798/java/jetbrains-kotlin-jvm-language-appeals-to-the-java-faithful.html#tk.rss_all

Fold

Mi ci è voluta più di qualche imprecazione per arrivare a questa implementazione :

fun Shop.getSetOfProductsOrderedByEveryCustomer(): Set<Product> {
    return customers.fold(allOrderedProducts, {
        orderedByAll, customer -> 
orderedByAll.minus( orderedByAll.filter { !customer.orderedProducts.contains(it) }) })
}

Salvo poi scoprire nelle soluzioni che esisteva il magico intersect

fun Shop.getSetOfProductsOrderedByEveryCustomer(): Set<Product> {
    // Return the set of products ordered by every customer
    return customers.fold(allOrderedProducts, {
        orderedByAll, customer ->
        orderedByAll.intersect(customer.orderedProducts)
    })
}

L’esercizio era questo : https://github.com/Kotlin/kotlin-koans/blob/master/src/ii_collections/_22_Fold_.kt

Comunque Kotlin è bellissimo.