Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Welcome to the world of functional programming! If you're feeling *really* hardcore then check out Haskell!
-
Poolarn28yThis can be done in Java using SAM-interfaces and anonymous implementations as function parameters. Or using Java-8 lambdas for a nicer syntax!
https://dzone.com/articles/...
Without lambdas it is not the most beautiful thing in the world but it still works great :) -
Java 8 lambdas are great. Using a map from an enum or string to a lambda expression to call the appropriate function is great. For example, for alternate id searches I have something like:
idToRepoMap.add(IDEnum.id1, repo::findById1);
idToRepoMap.add(IDEnum.id2, repo::findById2);
And to call it it is something like idToRepoMap.get(idType).apply(value).
Way cleaner than
switch idType:
case IDEnum.id1:
case IDEnum.id2:
...
I'm mainly a Java guy but JS ability to pass a function has a parameter to another function makes me feel like god.
undefined
javascript
wk20