Removes and returns the first matching element, or returns null if there is none.
(Iterable<T> removeFrom, Predicate<? super T> predicate)
| 251 | */ |
| 252 | |
| 253 | @Nullable |
| 254 | static <T> T removeFirstMatching(Iterable<T> removeFrom, Predicate<? super T> predicate) { |
| 255 | checkNotNull(predicate); |
| 256 | Iterator<T> iterator = removeFrom.iterator(); |
| 257 | while (iterator.hasNext()) { |
| 258 | T next = iterator.next(); |
| 259 | if (predicate.apply(next)) { |
| 260 | iterator.remove(); |
| 261 | return next; |
| 262 | } |
| 263 | } |
| 264 | return null; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Determines whether two iterables contain equal elements in the same order. |
no test coverage detected