Made this function, but I feel like the name (and ...
# naming
s
Made this function, but I feel like the name (and possibly the signature) can be improved. I use this alot (e.g.
foos.find { it.id == id }
) so this is nice sugar for me (used like
foos.findBy(id) { it.id }
):
Copy code
inline fun <T, R> Iterable<T>.findBy(key: R, selector: (T) -> R): T? = find { selector(it) == key }
Maybe rename to just
find
?
findIn
?
j
Why do you find this custom function better? It saves 0 characters, you still have to have both the property access and the value, and it's one more thing the reader will have to figure out (as opposed to stdlib functions).