Luis
02/11/2022, 3:09 PMfun find(session: Session, query: Query) {}
fun find(query: Query) {}
Is there a cleaner way than this to pick which one to use?
fun caller(session: Session?) {
val query = Query()
if (session == null) {
return find(query)
}
return find(session, query)
}
Thanks!Alexander Maryanovsky
02/11/2022, 3:11 PMfind
with a default null
value for the session
parameter, and call it from everywhere.Alexander Maryanovsky
02/11/2022, 3:13 PMfun myFind(query: Query, session: Session? = null) = if (session == null) find(query) else find(session, query)
Luis
02/11/2022, 3:14 PMfind
function?Alexander Maryanovsky
02/11/2022, 3:16 PMfind
functions, so whatever you write, it will at least have the two expressions find(session, query)
and find(query)
. Given that, how much shorter than
if (session == null) find(query) else find(session, query)
can you go?Luis
02/11/2022, 3:20 PMTies
02/11/2022, 7:40 PMAlexander Maryanovsky
02/13/2022, 9:33 PMfind(it, query)
returns null
, you will end up calling find(query)
too.Ties
02/14/2022, 8:05 AM