Interface MappableIterable<T>

Type Parameters:
T - The type of elements returned by the iterator. Note that it is strongly recommended to not ever return null; consider using Optional instead of that.
All Superinterfaces:
Iterable<T>
All Known Implementing Classes:
CoreSubsets, DoubleMapIterable, EIEIODataMessage, Machine, ProgressIterable, ReaderLineIterable, Router, TripleMapIterable, VirtualMachine

public interface MappableIterable<T>
extends Iterable<T>
Extends iterable with the ability to be mapped to different values.
Author:
Donal Fellows
  • Method Details

    • map

      default <U> MappableIterable<U> map​(Function<T,​U> mapper)
      Apply a function to an iterable to get another iterable.
      Type Parameters:
      U - The type of the elements of the created iterable.
      Parameters:
      mapper - The function to apply. Should not return null.
      Returns:
      The new iterable, which may also be mapped.
    • filter

      default MappableIterable<T> filter​(Predicate<T> filterer)
      Apply a filter to an iterable to get another iterable. Note that this assumes that null is never produced as a value that should be produced in the resulting iterable.
      Parameters:
      filterer - The filter function to apply.
      Returns:
      The new iterable, which only contains elements for which filterer returns true and which are not null.
    • first

      default Optional<T> first()
      Get the first item in the iterable, if there is one.
      Returns:
      an optional with the first item.
    • first

      default MappableIterable<T> first​(int n)
      Get another iterable with the first n item in the iterable (or up to that if the source iterable has fewer items).
      Parameters:
      n - the maximum number of items of the iterable that are wanted
      Returns:
      the first n items.
    • nth

      default Optional<T> nth​(int n)
      Index into the iterable.
      Parameters:
      n - The index into the iterable. Zero-based.
      Returns:
      The item at that index, should it exist.
    • toList

      default List<T> toList()
      Convert this iterable to a list. The order of elements in the list will be the same as the order of items in this iterable.
      Returns:
      A list of the elements in the iterable. Note that this must be finite! This list is not modifiable.
    • toList

      default List<T> toList​(Supplier<List<T>> supplier)
      Convert this iterable to a list. Items will be added to the list in the order of this iterable.
      Parameters:
      supplier - How to make the list itself.
      Returns:
      A list of the elements in the iterable. Note that this must be finite! This list is not modifiable.
    • toSet

      default Set<T> toSet()
      Convert this iterable to a set. The natural order of elements in the set will be the same as the order of items in this iterable.
      Returns:
      A set of the elements in the iterable. Note that this must be finite! This set is not modifiable.
    • toSet

      default Set<T> toSet​(Supplier<Set<T>> supplier)
      Convert this iterable to a set. Items will be added to the set in the order of this iterable.
      Parameters:
      supplier - How to make the set itself.
      Returns:
      A set of the elements in the iterable. Note that this must be finite! This set is not modifiable.
    • toMap

      default <K,​ V> Map<K,​V> toMap​(Function<T,​K> keyMapper, Function<T,​V> valueMapper)
      Convert this iterable to a map. The natural order of entries will be the same as the natural order of elements in this iterable.
      Type Parameters:
      K - The type of keys.
      V - The type of values.
      Parameters:
      keyMapper - How to get a key from an element of the iterable.
      valueMapper - How to get a value from an element of the iterable.
      Returns:
      A map derived from elements in the iterable. Note that this must be finite! This map is not modifiable.
    • toMap

      default <K,​ V> Map<K,​V> toMap​(Supplier<Map<K,​V>> supplier, Function<T,​K> keyMapper, Function<T,​V> valueMapper)
      Convert this iterable to a map. Items will be added to the map in the order of this iterable.
      Type Parameters:
      K - The type of keys.
      V - The type of values.
      Parameters:
      supplier - How to make the map itself.
      keyMapper - How to get a key from an element of the iterable.
      valueMapper - How to get a value from an element of the iterable.
      Returns:
      A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
    • toCollectingMap

      default <K,​ V> Map<K,​List<V>> toCollectingMap​(Function<T,​K> keyMapper, Function<T,​V> valueMapper)
      Convert this iterable to a map of lists. Items will be added to the map and to the lists in the order of this iterable.
      Type Parameters:
      K - The type of keys.
      V - The type of leaf values.
      Parameters:
      keyMapper - How to get a key from an element of the iterable.
      valueMapper - How to get a leaf value from an element of the iterable.
      Returns:
      A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
    • toCollectingMap

      default <K,​ E extends Enum<E>> Map<K,​EnumSet<E>> toCollectingMap​(Class<E> cls, Function<T,​K> keyMapper, Function<T,​E> valueMapper)
      Convert this iterable to a map of sets of enum values. Items will be added to the map in the order of this iterable.
      Type Parameters:
      K - The type of keys.
      E - The type of leaf values.
      Parameters:
      cls - The class of leaf values.
      keyMapper - How to get a key from an element of the iterable.
      valueMapper - How to get a leaf value from an element of the iterable.
      Returns:
      A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
    • toCollectingMap

      default <K,​ V,​ S extends Collection<V>> Map<K,​S> toCollectingMap​(Supplier<S> supplier, Function<T,​K> keyMapper, Function<T,​V> valueMapper)
      Convert this iterable to a map of collections. Items will be added to the map and to the collections in the order of this iterable.
      Type Parameters:
      K - The type of keys.
      V - The type of leaf values.
      S - The type of per-key collectors.
      Parameters:
      supplier - How to make the value collectors.
      keyMapper - How to get a key from an element of the iterable.
      valueMapper - How to get a leaf value from an element of the iterable.
      Returns:
      A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
    • toCollectingMap

      default <K,​ V,​ S extends Collection<V>> Map<K,​S> toCollectingMap​(Supplier<Map<K,​S>> mapSupplier, Supplier<S> collectorSupplier, Function<T,​K> keyMapper, Function<T,​V> valueMapper)
      Convert this iterable to a map of collections. Items will be added to the map and to the collections in the order of this iterable.
      Type Parameters:
      K - The type of keys.
      V - The type of leaf values.
      S - The type of per-key collectors.
      Parameters:
      mapSupplier - How to make the map itself.
      collectorSupplier - How to make the value collectors.
      keyMapper - How to get a key from an element of the iterable.
      valueMapper - How to get a value from an element of the iterable.
      Returns:
      A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.