Kotlin ♥

One of my greater subsystems written in java was a task-chaining architecture. A runner that takes a task and then executes it, the task then looks if it is chained to another task and executes that task first to get the result from that task as it’s input value. Very much like the a unix pipe, it’s actually what I tried to create.

There are some shortcomings of this solution, mainly when creating/chaining tasks together you have to do it backwards which isn’t fun, but that’s another topic.

One of the standardized tasks I have written is a modify-task that takes and produces the same generic type. Like a filter, sort or similar function. It was when I went over some code to translate the classes that implemented that interface I both got sad and glad at the same time.

Glad because it’s so much simpler to do in kotlin (or java8 to be fair) and sad cause I had made this structure very useful and smart. And now it’s obsolete..

The original filter (java6)

public class Archived implements IModify<List<IProgram>> {
private final boolean _archived;

public ArchivedFilter( boolean archived ) {
_archived = archived;
}

@Override
public List<IProgram> modify( final List<IProgram> list ) {
List<IProgram> result = new ArrayList<>();
for( IProgram program : list ) {
if( program.isArchived() == _archived ) {
result.add( program );
}
}
return result;
}
}

And in kotlin

class Archived( val archived:Boolean ):IModify<List<IProgram>> {
override fun modify( list:List<IProgram> ) =
list.filter { it.isArchived == archived }
}

Happy days!
→ Bob

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.