https://kotlinlang.org logo
#announcements
Title
# announcements
k

karelpeeters

08/02/2017, 9:37 PM
There no version of
also
that ignores the receiver, right? Something that fits here:
Copy code
return call().ignore{ //no it or this here }
k

kingsley

08/02/2017, 9:38 PM
What will be the purpose then?
d

diesieben07

08/02/2017, 9:38 PM
return try { call() } finally { ... }
maybe?
k

kingsley

08/02/2017, 9:39 PM
return run { call(); /* more stuuff */ }
k

karelpeeters

08/02/2017, 9:39 PM
@kingsley Specifically to run some code just before returning.
k

kingsley

08/02/2017, 9:40 PM
Well. You could just use
apply
or
also
and ignore the receiver
k

karelpeeters

08/02/2017, 9:40 PM
Yea I was doing that but the I wondered if there was a better way.
k

kingsley

08/02/2017, 9:40 PM
Or well. Create your own extension function
d

diesieben07

08/02/2017, 9:41 PM
How about:
Copy code
val result = call()
// do stuff
return result
Nothing wrong with locals 😉
k

karelpeeters

08/02/2017, 9:42 PM
My code if flooded with `result`s already ☺️
k

kingsley

08/02/2017, 9:42 PM
Copy code
inline fun <T> T.ignore(block: () -> Unit): T {
  block()
  return this
}
k

karelpeeters

08/02/2017, 9:43 PM
I'll probably settle for something like that indeed.
i

ilya.gorbunov

08/03/2017, 12:38 AM
You can use
also
and ignore the parameter naming it with
_
placeholder:
Copy code
call().also { _ -> .... }
2 Views