Switching from Essentials4J to Kotlin

At work we have a project that used Essentials4J, and its predecessor Rapidoid Fluent, to simplify some stream/collection APIs. We have been converting this project to Kotlin, and no longer need that library. The conversion was very simple. It highlights some of the things you can do with collections with Kotlin’s standard library.

Do.group(…).by(…)

List<Thing> things = new ArrayList<Thing>();//add some things to it
Map<String, List<Thing>> byName = Do.group(things).by(Thing::getName);
val things = mutableListOf<Thing>()
val byName = things.groupBy { it.name }

Do.map(…).to(…)

List<Thing> things = new ArrayList<Thing>();
List<Thing> names = Do.map(things).to(Thing::getName)
val names: List<String> = things.map { it.name }

Do.map(…).to(…) with unique values

Map<Integer, Thing> mapped = Do.map(things).to(Thing::getId, p -> p);
val mapped: Map<Int,Thing> = things.associateBy { it.id }

d639a7ccf9252433

Leave a Reply