So I have defined a partial function to be used for collectFirst method in collection:
myList.collectFirst{
case A(_,_,_) => ....
case B(_,_,_) => ....
case C(_,_,_) => ....
}
If myList contains A,B,C all then which case would be executed?
So I have defined a partial function to be used for collectFirst method in collection:
myList.collectFirst{
case A(_,_,_) => ....
case B(_,_,_) => ....
case C(_,_,_) => ....
}
If myList contains A,B,C all then which case would be executed?
Copyright © 2021 Jogjafile Inc.
The documentation for
collectFirstsaid the following:Let's assume
val myList = List(A(...), B(...), C(...)). In that casecase A(_, _, _)will be executed. If we haveval myList = List(B(...), A(...), C(...))then the second case will be executed becauseB(...)is the first element satisfied the partial fucntion.