Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Better way to access tuple(other than match case)

Tags:

scala

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

    User.findUserJoinAclTree(3).map {

        _ match {

            case(user, acl, tree) =>

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

        }                   

    }
like image 316
Drew H Avatar asked Mar 09 '12 15:03

Drew H


1 Answers

Your expression can be simplified a bit:

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

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

like image 69
paradigmatic Avatar answered Sep 24 '22 02:09

paradigmatic