Returns an {@link Optional} containing the first element in this fluent iterable. If the iterable is empty, {@code Optional.absent()} is returned. <p><b>{@code Stream} equivalent:</b> if the goal is to obtain any element, {@link Stream#findAny}; if it must specifically be the <i>first</i> element,
()
| 510 | * iterator().next()} or {@link Iterables#getFirst} instead. |
| 511 | */ |
| 512 | @SuppressWarnings("nullness") // Unsafe, but we can't do much about it now. |
| 513 | public final Optional<@NonNull E> first() { |
| 514 | Iterator<E> iterator = getDelegate().iterator(); |
| 515 | return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.absent(); |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Returns an {@link Optional} containing the last element in this fluent iterable. If the |