Storing When Block Subject in a Variable

Here is a super short post on a change introduced in Kotlin 1.3 (yes, I know it has been out for a while now). We will take a quick look at capturing the subject of a when block into a scoped variable. This is a quality of life improvement that saves a line or so of code while making the role of the variable clearer.

Below is what you would write before the change: