Apache Beam + Kotlin = ❤️

Harshit Dwivedi
Aug 23 · 2 min read

Code Snippets

String Templating

String filename = String.format(
// String templating
val filename = "$filenamePrefix-$shardNumber-of-$numShards"

Single Line Functions

public static class FormatAsTextFn extends SimpleFunction<KV<String, Long>, String> {
public String apply(KV<String, Long> input) {
return input.getKey() + ": " + input.getValue();
public class FormatAsTextFn : SimpleFunction<KV<String, Long>, String>() {
override fun apply(input: KV<String, Long>) = "${input.key} : ${input.value}" //Single line functions

Null Checks

if(tableRow != null){
formatAndInsert(it) // No need for null checks

Type Inferencing

String tableName = "testTable";
val tableName = "testTable"  // Type inferencing

Contributors Welcomed!

Harshit Dwivedi

Written by

Android Developer, has an *approximate* knowledge of many things. https://harshit.app/

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade