Sam Stone
08/02/2022, 7:48 AMfun <T> ld(t: T, getMessage: (T) -> String) = Timber.d(getMessage(t))
and fun <T> T.ld() = this.also { Timber
.d(it) }
The issue is that the class is always the util class. Writing val
`ld = {(insert previous code)
}` works for the former wrapper, but not the latter. I use the latery for chaining.Trevor Stone
08/02/2022, 5:13 PMval <T> T.ld: T.() -> T
get() = { this.also { println(it) } }
Does this work?123.ld()
Sam Stone
08/05/2022, 3:13 AMTrevor Stone
08/05/2022, 1:25 PMSam Stone
08/05/2022, 4:05 PMgetMessage
?fun <T, R> T.ld(message: R) = this.apply { Timber.d(message.toString()) }
Trevor Stone
08/05/2022, 4:13 PMSam Stone
08/07/2022, 2:41 PMTimber.d()
as ld()
. Because fun ld()
is desclared in my utils class, the class reported in the logs is always my utils class, which completely removes the usefulness of that function, and the logs are harder to read. I am trying to find a way to call this function in a way that it will capture the class it was called in. I think wrapping the function in a lambda, and calling the lambda in the calling class will capture that class in the log (haven’t tried yet). One of the wrappers takes the receiver of T.ld()
and passes it to the lambda (e.g. "a".ld { "the letter is: $it" }
).