Intermediate Operations
distinct() : Remove duplicates
distinct() : Remove duplicatesReturns a stream consisting of the distinct elements of this stream.
Stream.of([1, 1, 2, 3]) \
.distinct() \
.to_list() # [1, 2, 3]drop_while() : Drop elements while the predicate is true
drop_while() : Drop elements while the predicate is trueReturns, if this stream is ordered, a stream consisting of the remaining elements of this stream after dropping the longest prefix of elements that match the given predicate.
Stream.of([1, 2, 3]) \
.drop_while(lambda x: x < 3) \
.to_list() # [3]filter() : Restrict the Stream
filter() : Restrict the StreamReturns a stream consisting of the elements of this stream that match the given predicate.
Stream.of([1, 2, 3, None]) \
.filter(lambda x: x is not None) \
.for_each(print) # 1 2 3flat_map() : Streams in Streams
flat_map() : Streams in StreamsReturns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.
group_by(): Group the stream by a given key
group_by(): Group the stream by a given keyReturns a stream consisting of the elements of this stream, grouped by the given classifier and extracting the key/value pairs.
limit() : Limit the Stream to a certain number of elements
limit() : Limit the Stream to a certain number of elementsReturns a stream consisting of the elements of this stream, truncated to be no longer than max_size.
map() : Convert the elements in the Stream
map() : Convert the elements in the StreamReturns a stream consisting of the results of applying the given function to the elements of this stream.
map_to_float() : Convert the elements in the Stream to a Float
map_to_float() : Convert the elements in the Stream to a FloatReturns a NumericStream consisting of the results of applying the float() function to the elements of this stream. Note that this method is not none safe.
map_to_int() : Convert the elements in the Stream to an Integer
map_to_int() : Convert the elements in the Stream to an IntegerReturns a NumericStream consisting of the results of applying the int() function to the elements of this stream. Note that this method is not none safe.
map_to_str() : Convert the elements in the Stream to a String
map_to_str() : Convert the elements in the Stream to a StringReturns a stream consisting of the results of applying the str() function to the elements of this stream.
numeric() : Convert the stream to a NumericStream
numeric() : Convert the stream to a NumericStreamReturns a NumericStream consisting of the same elements as the stream contained before conversion.
parallel() : Convert the stream to a ParallelStream
parallel() : Convert the stream to a ParallelStreamReturns a ParallelStream consisting of the same elements as the stream contained before conversion.
peek() : View intermediate results
peek() : View intermediate resultsReturns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.
reversed() : Reverse Stream
reversed() : Reverse StreamReturns a stream consisting of the elements of this stream in reverse order.
sequential() : Convert the stream to a SequentialStream
sequential() : Convert the stream to a SequentialStreamReturns a SequentialStream consisting of the same elements as the stream contained before conversion.
skip() : Skip the first n elements of the Stream
skip() : Skip the first n elements of the StreamReturns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream.
sorted() : Sort Stream
sorted() : Sort StreamReturns a stream consisting of the elements of this stream, sorted according to natural order or comparator.
Here is an example with a custom comparator:
take_while() : Take elements while the predicate is true
take_while() : Take elements while the predicate is trueReturns, if this stream is ordered, a stream consisting of the longest prefix of elements taken from this stream that match the given predicate.
Last updated
Was this helpful?