Defining an Operator Invoke Extension Function on Kotlin Function Types

I’ve been producing a lot of YouTube Videos lately. They’re about refactoring and TDD and all that good stuff - you really should subscribe.

In one episode I have a class that takes a function type property in its constructor. The property defines a strategy for how to update items.

Here I’m going to go off on the tangent that Jekyll’s home-page generation fails if you have a code block that is split on the front page. So this...

more

Writing Software to Write About Writing Software - Part 1

O’Reilly recently published the Kotlin book I wrote with Nat Pryce: Java to Kotlin: A Refactoring Guidebook. I thought it might be interesting to write about the software we wrote to support our writing.

O’Reilly’s publishing system (Atlas) will accept Word, DocBook or AsciiDoc manuscripts. My experience trying to manage simultaneous work in large Word documents has not been great, although perhaps Office 365 is better - I’ve been generally impressed when I have used it. Being developers...

more

Extracting an Extension Function from a Call Chain

Kotlin extension functions let us express our algorithms as functional pipelines. We can see these as chains of calls, where the output of a stage is fed into the next. Here’s a chain that reads lines representing CustomerData from a reader:

val valuableCustomers = reader .buffered() .lineSequence() .drop(1) // header .map(String::toCustomerData) .filter { it.score >= 10 } .sortedBy(CustomerData::score) .toList() 

Chains like this are nice and easy to read (at least for English speakers), as we start at the...

more

Inline Tiny Types With Validation

It’s been a long time since my last post. This is largely because my writing efforts have been directed towards a book! Nat Pryce (co-author of the excellent GOOS) and I are hard at work on Java to Kotlin, A Refactoring Guidebook, due to be published in 2021 by O’Reilly. You can read our work in progress on O’Reilly Online Learning.

Nat and I are both fans of tiny-types. The basic idea here is to have a...

more

Fun With Maps Part 2

Recap

In the previous episode, we looked at parsing a log file. We initially used data classes to represent the different types of events that we saw, but found that they could be clumsy when representing type hierarchies, and we had to fall back on reflection in order to select properties specified by strings.

In contrast using maps to represent the data was (in this instance) less awkward, and they made it easy to select properties by name....

more