Humble Kotlin and Rx solutions (not suggestion)

Note: When I wrote this article I was trying to solve a problem that I thought existed. One day later, I know the problem don’t exist. But hey, it gave me a coding challenge and I learned something from it =)
So I’ll keep it around, with the solutions in the bottom.

fun canWeUseIt( value:Any ) {
if( value is String ) {
// I don't want to cast value here, I know it's a String
}
}
listOf( 1, "Two", 3 )
.filter { it is String }
.first() // Why doesn't this return a String instead of Any?
Observable.just( 1, "Two", 3 )
.filter { it is String }
.blockingFirst() // Still the type Any...
fun <T,U:T> Observable<T>.filterMap( cls:Class<U> ):Observable<U> { 
return filter { cls.isInstance( it ) }
.map { cls.cast( it ) }
}

Lead Developer at Qvik, Coach, Agile Thinker, GDG Lead.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store