12
crani
8y

I'm mainly a Java guy but JS ability to pass a function has a parameter to another function makes me feel like god.

Comments
  • 2
    Check out Scala. It's really cool, and jvm based!
  • 2
    Welcome to the world of functional programming! If you're feeling *really* hardcore then check out Haskell!
  • 2
    This 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 :)
  • 3
    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:

    ...
  • 0
    Passed a function as an argument to another function in swift... Piece of cake
Add Comment