I have a var of type ArrayBuffer.
var selected = new ArrayBuffer[Component](0)
I would like to extract from it the first element which satisfies a given condition.
var res = selected.filter(_.node == neighbour)(0)
I want something like the line above, but in case no element satisfies that condition, I want res to be null. Instead, the code is throwing an error.
How can I get the first element satisfying the condition or null?