Emanuel Moecklin
1 min readMay 5, 2020

--

The lodash way is definitely a good way to implement this simple function. Combining object oriented programming and functions gives you however an even more concise and imo more readable way (Kotlin):

val applePrice = fruits.firstOrNull { it.name == "Apple" }?.price

Instead of using an external library (needs to be imported) and applying two _ functions to objects (fruits and fruit), above code works directly on the list of fruits (oop). My point here is that the art of computer programming is about picking the right tool for the problem and if it’s combining two paradigms then I’ll do that. IMO the original article (and a lot of the references) focus too much on language specific shortcomings. The real problem is not oop or functional programming, it’s the languages and developers that don’t use them properly.

--

--