Returns a fluent iterable that wraps {@code iterable}, or {@code iterable} itself if it is already a {@code FluentIterable}. <p><b>{@code Stream} equivalent:</b> {@link Collection#stream} if {@code iterable} is a {@link Collection}; {@link Streams#stream(Iterable)} otherwise.
(Iterable<E> iterable)
| 137 | * Collection}; {@link Streams#stream(Iterable)} otherwise. |
| 138 | */ |
| 139 | public static <E extends @Nullable Object> FluentIterable<E> from(Iterable<E> iterable) { |
| 140 | return (iterable instanceof FluentIterable) |
| 141 | ? (FluentIterable<E>) iterable |
| 142 | : new FluentIterable<E>(iterable) { |
| 143 | @Override |
| 144 | public Iterator<E> iterator() { |
| 145 | return iterable.iterator(); |
| 146 | } |
| 147 | }; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Returns a fluent iterable containing {@code elements} in the specified order. |