Terminal Operations
all_match() : Check if all elements match a predicate
all_match() : Check if all elements match a predicateReturns whether all elements of this stream match the provided predicate.
Stream.of([1, 2, 3]) \
.all_match(lambda x: x > 0) # Trueany_match() : Check if any element matches a predicate
any_match() : Check if any element matches a predicateReturns whether any elements of this stream match the provided predicate.
Stream.of([1, 2, 3]) \
.any_match(lambda x: x < 0) # Falsecount() : Count the number of elements in the Stream
count() : Count the number of elements in the StreamReturns the number of elements in this stream.
Stream.of([1, 2, 3]) \
.count() # 3find_any() : Find an element in the Stream
find_any() : Find an element in the StreamReturns an Optional describing an arbitrary element of this stream, or an empty Optional if the stream is empty.
Stream.of([1, 2, 3]) \
.find_any() # Optional[1]find_first() : Find the first element in the Stream
find_first() : Find the first element in the StreamReturns an Optional describing the first element of this stream, or an empty Optional if the stream is empty.
Stream.of([1, 2, 3]) \
.find_first() # Optional[1]for_each() : Perform an action for each element in the Stream
for_each() : Perform an action for each element in the StreamPerforms the provided action for each element of this stream.
Stream.of([1, 2, 3]) \
.for_each(print) # 1 2 3none_match() : Check if no element matches a predicate
none_match() : Check if no element matches a predicateReturns whether no elements of this stream match the provided predicate.
Stream.of([1, 2, 3]) \
.none_match(lambda x: x < 0) # Truemin() : Find the minimum element in the Stream
min() : Find the minimum element in the StreamReturns the minimum element of this stream
Stream.of([1, 2, 3]) \
.min() # 1max() : Find the maximum element in the Stream
max() : Find the maximum element in the StreamReturns the maximum element of this stream
Stream.of([1, 2, 3]) \
.max() # 3reduce() : Reduce the Stream to a single value
reduce() : Reduce the Stream to a single valueReturns the result of reducing the elements of this stream to a single value using the provided reducer.
Stream.of([1, 2, 3]) \
.reduce(lambda x, y: x + y) # 6to_dict() : Convert the Stream to a dictionary
to_dict() : Convert the Stream to a dictionaryReturns a dictionary containing the elements of this stream by applying the given classifier.
Stream.of([(1, 2), (1, 6), (2, 3), (2, 8), (3, 0)]) \
.to_dict(lambda p: p[0]) # {1: [(1, 2), (1, 6)], 2: [(2, 3), (2, 8)], 3: [(3, 0)]}to_list() : Convert the Stream to a List
to_list() : Convert the Stream to a ListReturns a list containing the elements of this stream.
Stream.of([1, 2, 3]) \
.to_list() # [1, 2, 3]to_set() : Convert the Stream to a Set
to_set() : Convert the Stream to a SetReturns a set containing the elements of this stream.
Stream.of([1, 2, 3]) \
.to_set() # {1, 2, 3}to_tuple() : Convert the Stream to a Tuple
to_tuple() : Convert the Stream to a TupleReturns a tuple containing the elements of this stream.
Stream.of([1, 2, 3]) \
.to_tuple() # (1, 2, 3)Last updated
Was this helpful?