Is it standard practice to name a `fun interface` ...
# codingconventions
m
Is it standard practice to name a
fun interface
as a verb when the function is
invoke
? Or maybe as a noun like here:
Copy code
fun interface ItemSelector {
    operator fun invoke(items: List<String>): String
}

val selectItem = object : ItemSelector { ... }
val itemSelected = selectItem( ... )
1. Verb 2. Noun
p
If I had a
fun interface operator fun invoke
, I would probably just use a typealias instead
Although as you're using it in that example I think 'as a noun' makes sense
https://pl.kotl.in/iW9VEDZ-k Typealias vs fun interface
m
Thanks Paul. I think the main downside of typealias is that named arguments are not allowed.
p
Does your selector function actually need the context of all elements? I think a more idiomatic style would be to implement a predicate interface (less common), or just match the signature (more common) - that has the benefit of slotting into a bunch of common collection operations automatically: https://pl.kotl.in/u29AcEU-j
m
I’m not actually dealing with collections. This was just a random example off the top of my head.
👍 1
s
naming interfaces in general as agent nouns is something folks have been doing for a while; I think it’s a fine convention to keep in this case