The best way to access a tuple (except in the case of a match)

I have this code. The method returns a tuple (User, Acl, Tree). Instead of accessing data with _._1, _._2, etc. I use a match. Is there an easier (better) way than what I'm doing? thank

    User.findUserJoinAclTree(3).map {

        _ match {

            case(user, acl, tree) =>

                Logger.info(user.email)
                Logger.info(acl.id)
                Logger.info(tree.name)

        }                   

    }
+5
source share
2 answers

Your expression may be slightly simplified:

User.findUserJoinAclTree(3) map {
  case (user,_,_) => Logger.info(user.email)
}                   

First, you don’t need to match arguments, you can directly pass a partial function to match, then you can use the wildcard (_) for tuple elements that you don’t need.

+9
source

In this particular case

for ((user,_,_) <- User.findUserJoinAclTree(3)) yield Logger.info(user.email)
+5
source

All Articles