private @ Nonnull Optional < XQuery > findElement ( Function < Node , Node > iterator ) { Node it = node ; do { it = iterator . apply ( it ) ; } while ( it != null && ! ( it instanceof Element ) ) ; return Optional . ofNullable ( it ) . map ( XQuery :: new ) ; }
Finds an Element node by applying the iterator function until another Element was found .