https://kotlinlang.org logo
Title
a

Andrew Gazelka

01/29/2019, 12:04 AM
is there a standard of when to use higher order functions vs interfaces with one method?
maybe it is just me, but
val permissions = HashSet<(CommandSender) -> Boolean>()
seems slightly jank
also HOF don't really specify what the function is doing whereas interfaces do
is having two functions, one accepting an interface and one accepting a HOF redundant? (HOF would be wrapped in interface)
s

Shawn

01/29/2019, 12:05 AM
conversely, interfaces generally don’t tell you what the function takes and returns
if you find yourself writing this type out a lot, maybe a typealias is a good middle ground?
a

Andrew Gazelka

01/29/2019, 12:11 AM
yeah, probably
g

ghedeon

01/29/2019, 2:08 AM
honestly, seems like HOF is often preferable even in case of interfaces with multiple functions. It's more granular and flexible this way. A good example would be
TextWatcher
on Andorid that got splitted into separate lambdas in ktx library.