Java Stream Extras

Extras for Java 8+ streams.

License

License

GroupId

GroupId

ca.redtoad
ArtifactId

ArtifactId

javastream-extras
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Java Stream Extras
Extras for Java 8+ streams.

Download javastream-extras

How to add to project

<!-- https://jarcasting.com/artifacts/ca.redtoad/javastream-extras/ -->
<dependency>
    <groupId>ca.redtoad</groupId>
    <artifactId>javastream-extras</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/ca.redtoad/javastream-extras/
implementation 'ca.redtoad:javastream-extras:1.0'
// https://jarcasting.com/artifacts/ca.redtoad/javastream-extras/
implementation ("ca.redtoad:javastream-extras:1.0")
'ca.redtoad:javastream-extras:jar:1.0'
<dependency org="ca.redtoad" name="javastream-extras" rev="1.0">
  <artifact name="javastream-extras" type="jar" />
</dependency>
@Grapes(
@Grab(group='ca.redtoad', module='javastream-extras', version='1.0')
)
libraryDependencies += "ca.redtoad" % "javastream-extras" % "1.0"
[ca.redtoad/javastream-extras "1.0"]

Dependencies

test (2)

Group / Artifact Type Version
org.codehaus.groovy : groovy-all jar 2.4.13
org.spockframework : spock-core jar 1.0-groovy-2.4

Project Modules

There are no modules declared in this project.

Extras for Java 8+ Streams

Build Status DepShield Badge

This provides some extra collectors to use with Java 8+ streams.

The collectors provided are:

  1. RandomValueCollector - returns one random value from from the stream. Each item has an equal probability of being returned. If the stream is empty, Optional.empty() is returned.

  2. TopNCollector - returns the top N values in the stream. If the stream contains fewer than N items, the entire stream is returned. The stream value type must implement the Comparable interface.

Code Examples

 // collect one value from the stream where each value has equal
 // probability of being chosen
 IntStream.range(1, 20).boxed().collect(new RandomValueCollector())

 // collect only the top 5 values using the objects natural ordering
 IntStream.range(1, 20).boxed().collect(new TopNCollector(5))

Versions

Version
1.0