Skip to content

Type Interfaces : Traversable

johnmcclean-aol edited this page Nov 22, 2016 · 1 revision

The Traversable interface

A Traversable represents an Iterable type and adds useful functionality that can be applied to any Iterable type.

Traversable contains a large range of utility methods including - operators are lazy if the traversable is lazy.

  • combine : partial reduction operator, use this for lazy / terminating reduction or folding of infinite data structures
  • cycle : repeats the data inside the traversable
  • groupedXXX : groups the data in the traversable
  • slidingXXX : create sliding windows over the data in the traversable
  • onEmpty : gracefully handle an empty traversable
  • scanLeft / scanRight : fold over the traversable creating a new traversable of the intermediate outputs
  • takeXXX / dropXXX : advanced take / drop operators

Examples

ReactiveSeq.generate(this::process)
           .map(data->data.isSuccess())
           .combine((a,b)-> a ? false : true, (a,b) -> a|b)
           .findFirst(); //terminating reduction on infinite data structure

ListX.of(1,2,3)
     .dropRight(1);

//ListX[1,2]
     

Implementations

CollectionXImpl, CompletableFutureTSeq, DequeXImpl, EvalTSeq, FutureWTSeq, ListTSeq, ListTValue, ListXImpl, MaybeTSeq, OptionalTSeq, PBagXImpl, POrderedSetXImpl, PQueueXImpl, PSetXImpl, PStackXImpl, PVectorXImpl, QueueXImpl, SetTSeq, SetTValue, SetXImpl, SortedSetXImpl, StreamableTSeq, StreamableTValue, StreamTSeq, StreamTValue, TryTSeq, XorTSeq

Clone this wiki locally