Cannot hack 1337 leet

Hello Mark,

Regarding

https://klassbook.commonsware.com/lessons/Functional%20Programming/functional-interface.html

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?

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 { it.id == 1337 })

…saying Interface Comparitizer does not have constructors.

Instead, you could write:

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

…but that is a lot more verbose.

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.