Given a traversable (sorry I don’t know which is the most general class) such as `Set`

or `List`

, I can use `find`

to identify an element for which a given unary predicate `f`

is satisfied, or whether such an element exists. However, given a binary predicate,`g:(A,B)=>Boolean`

how can I find the first (or any I don’t really care whether it is the first or not) element, (a,b) in A x B, such that `g(a,b) == true`

? I.e., some `a`

in `A`

and `b`

in `B`

for which `g(a,b)==true`

?

I can determine whether such exists using something like

```
A.exists(a => B.exists( b => g(a,b)))
```

And I could use two `var`

variables to track `a`

and `b`

. Then if the outer exists returns `true`

, then the tracking variables identify the pair. Is that the correct way?

```
def findAxB[U,V](A:List[U],B:List[V],g:(U,V)=>Boolean):Option[(U,V)] = {
var aa: U = A.head
var bb: V = B.head
if (A.exists { a: U => {
aa = a
B.exists { b: V => {
bb = b
g(a, b)
}
}
}
}
)
Some((aa, bb))
else
None
}
```

This could of course be optimized a bit using find/exists rather than exists/exists.