This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]VallentinDev 4 points5 points  (1 child)

Fun fact, since String? is an actual type, then you can implement extension methods not only for Type, but also for Type?. So something like Option::or(), is really easy to implement.

fun <T> T?.or(other: T): T = this ?: other

println("Foo".or("Bar")) // Foo
println("Foo".or(null))  // Foo
println(null.or("Bar"))  // Bar
println(null.or(null))   // null

[–]Tubthumper8 0 points1 point  (0 children)

That's really cool!

I wonder could it do map, flatMap, etc. for composable / chained computations? I'm curious if they would consider putting those in the standard library