Cannot hack 1337 leet

from the CommonsWare Community archives

At April 25, 2021, 3:16pm, ivano_trocchietto asked:

Hello Mark,


is written: “We do not need the object keyword and a full function declaration.”

I see that we give a lambda expression with the hollywood principle, do not ask, tell and I understand how the snippet works, but I am not able to “reverse” to make a snippet without the functional interface, maintaining a generic type and an interface. Please How would the snippet be without functional interface?

At April 25, 2021, 3:59pm, mmurphy replied:

If you just decide to not have fun:

interface Comparitizer<T> {
  fun valid(item: T): Boolean

…then you get a compile error in:

val leetEvent = firstItemOrNull(events, Comparitizer { == 1337 })

…saying Interface Comparitizer does not have constructors.

Instead, you could write:

	val leetEvent = firstItemOrNull(events, object : Comparitizer<Event> {
  		override fun valid(item: Event) = == 1337

…but that is a lot more verbose.

At April 25, 2021, 5:09pm, ivano_trocchietto replied:

englighting! thanks.

ps not fun is the way mystics always pointed out.
tao te ching chap 1:
Ever desireless, one can see the mystery.
Ever desiring, one can see the manifestations.
These two spring from the same source but differ in name;
this appears as darkness.
Darkness within darkness.
The gate to all mystery.