Reverse Your Arrows
Matthias
544

Enjoyed reading this, but mostly the typefull part. Option in Scala is very handy when you decide, that you don’t want to work with null type. In Java you could say, that type, if you imagine a type in form of a set, is almost always a subset of a set, that includes null value. Maybe a weird example but one could say, that in language with nullability your type named Weekday has 8 days (Mon, Tue, Wen, Thu, Fri, Sat, Sun & null). In this case, if you decide, that you would like to work with null value you can wrap it in form of NullableWeekday and with this we are getting almost where Option/Maybe type is. Kotlin language has this really great feature called sealed classes (you doesn’t see a lot a articles about this) where you can achive desirable behavior (actually there is not a much need for a Maybe type due to null-safety design of language) and even more. For some time I have been working with Either<Error, Value> type a-lot (for example network requests return this) with some extension functions and suddenly the code became more reasonable.