android - Kotlin 'it' syntax in the context of Volley -


can explain me how kotlin 'it' syntax in snippet of code works? code hard read, sent me fix problem , works magic multiple consecutive requests. have used volley before code confusing. believe kotlin easier read java particular code hard understand.

val responses = mutablelistof<jsonobject>() val myapiurl = "https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=" val myapikey = "removed" val transportmode = listof("&mode=driving", "&mode=walking", "&mode=bicycling",             "&mode=transit&transit_mode=bus", "mode=transit&transit_mode=subway", "mode=transit&transit_mode=train")  val queue = volley.newrequestqueue(this)  transportmode.map { "$myapiurl$locationcoordinateslat,$locationcoordinateslong&destinations=$locationinput$it&key=$myapikey" }             .map {                 jsonobjectrequest(request.method.get, it, null, response.listener {                     responses.add(it)                 }, response.errorlistener {                    //nothing                 })             }.foreach { queue.add(it) } } 

first, each entry in transportmode list mapped same string "$myapiurl$locationcoordinateslat,$locationcoordinateslong&destinations=$locationinput$it&key=$myapikey", throwing away transport mode. let's call a.

then, resulting list of these strings mapped jsonobjectrequests, url set it, 1 of strings a of list. each jsonobjectrequest has success callback , error callback. former receives resulting jsonobject implicit it parameter, responses.add(it) adds jsonobject list of responses.

the last it can found in lambda function passed foreach. it's 1 of jsonobjectrequest objects created in last map-step. lambda adds volley request queue.

to make things clearer, i've augmented code hints:

transportmode.map { mode -> "$myapiurl$locationcoordinateslat,$locationcoordinateslong&destinations=$locationinput$it&key=$myapikey" }         .map { url ->             jsonobjectrequest(request.method.get, url, null, response.listener { responsejsonobject ->                 responses.add(responsejsonobject)             }, response.errorlistener {                //nothing             })         }.foreach { request -> queue.add(request) } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -