I've just started learning Java stream API with kotlin and I'm using Project Reactor along with r2dbc API. I'm writing a simple code as given below and would appreciate in understanding how this works.
I want to know the line where t.let{}
returns a MovieCeleb object using return@map
. I want to know what this line does i.e., whether it creates a list/map and how it does this.
fun listAllMoviesBy(actor: String, client: DatabaseClient) {
client.execute()
.sql { "SELECT fin.id, full_name, movie_title, make_year, celeb_id, birth_date " +
"FROM featured_in fin JOIN film_celeb fc ON " +
" fin.celeb_id = fc.id WHERE fc.full_name = $1"
}.bind(0, actor).map { t, u ->
t.let {
val featuredIn = FeaturedIn(it.get("id") as Int, it.get("movie_title") as String, it.get("make_year") as Int)
val celeb = MovieCeleb(it.get("celeb_id") as Int, it.get("full_name") as String, it.get("birth_date") as LocalDate, featuredIn)
return@map celeb
}
}.all()
.subscribe{
println(it)
}
}