MCPcopy Index your code
hub / github.com/amaembo/streamex

github.com/amaembo/streamex @streamex-0.8.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release streamex-0.8.4 ↗ · + Follow
2,051 symbols 11,373 edges 94 files 527 documented · 26% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

StreamEx 0.8.4

Enhancing the Java Stream API.

Maven Central Javadocs Build Status Coverage Status

This library defines four classes: StreamEx, IntStreamEx, LongStreamEx, DoubleStreamEx that are fully compatible with the Java 8 stream classes and provide many useful additional methods. Also, the EntryStream class is provided which represents a stream of map entries and provides additional functionality for this case. Finally, there are some useful new collectors defined in MoreCollectors class as well as the primitive collectors concept.

Full API documentation is available here.

Take a look at the Cheatsheet for brief introduction to StreamEx!

Before updating StreamEx check the migration notes and the full list of changes.

StreamEx main points are the following:

  • Shorter and convenient ways to do common tasks.
  • Better interoperability with older code.
  • 100% compatibility with the original JDK streams.
  • Friendliness for parallel processing: any new feature takes advantage of parallel streams as much as possible.
  • Performance and minimal overhead. Whenever StreamEx allows solving a task using less code compared to the standard JDK Stream API, it should not be significantly slower than the standard way (and sometimes it's even faster).

Examples

Collector shortcut methods (toList, toSet, groupingBy, joining, etc.)

List<String> userNames = StreamEx.of(users).map(User::getName).toList();
Map<Role, List<User>> role2users = StreamEx.of(users).groupingBy(User::getRole);
StreamEx.of(1,2,3).joining("; "); // "1; 2; 3"

Selecting stream elements of a specific type

public List<Element> elementsOf(NodeList nodeList) {
    return IntStreamEx.range(nodeList.getLength())
      .mapToObj(nodeList::item).select(Element.class).toList();
}

Adding elements to a stream

public List<String> getDropDownOptions() {
    return StreamEx.of(users).map(User::getName).prepend("(none)").toList();
}

public int[] addValue(int[] arr, int value) {
    return IntStreamEx.of(arr).append(value).toArray();
}

Removing unwanted elements and using a stream as an Iterable:

public void copyNonEmptyLines(Reader reader, Writer writer) throws IOException {
    for(String line : StreamEx.ofLines(reader).remove(String::isEmpty)) {
        writer.write(line);
        writer.write(System.lineSeparator());
    }
}

Selecting map keys by value predicate:

Map<String, Role> nameToRole;

public Set<String> getEnabledRoleNames() {
    return StreamEx.ofKeys(nameToRole, Role::isEnabled).toSet();
}

Operating on key-value pairs:

public Map<String, List<String>> invert(Map<String, List<String>> map) {
    return EntryStream.of(map).flatMapValues(List::stream).invert().grouping();
}

public Map<String, String> stringMap(Map<Object, Object> map) {
    return EntryStream.of(map).mapKeys(String::valueOf)
        .mapValues(String::valueOf).toMap();
}

Map<String, Group> nameToGroup;

public Map<String, List<User>> getGroupMembers(Collection<String> groupNames) {
    return StreamEx.of(groupNames).mapToEntry(nameToGroup::get)
        .nonNullValues().mapValues(Group::getMembers).toMap();
}

Pairwise differences:

DoubleStreamEx.of(input).pairMap((a, b) -> b-a).toArray();

Support for byte/char/short/float types:

short[] multiply(short[] src, short multiplier) {
    return IntStreamEx.of(src).map(x -> x*multiplier).toShortArray(); 
}

Define a custom lazy intermediate operation recursively:

static <T> StreamEx<T> scanLeft(StreamEx<T> input, BinaryOperator<T> operator) {
        return input.headTail((head, tail) -> scanLeft(tail.mapFirst(cur -> operator.apply(head, cur)), operator)
                .prepend(head));
}

And more!

License

This project is licensed under Apache License, version 2.0

Installation

Releases are available in Maven Central

Before updating StreamEx check the migration notes and the full list of changes.

Maven

Add this snippet to your project's pom.xml dependencies section:

<dependency>
  <groupId>one.util</groupId>
  <artifactId>streamex</artifactId>
  <version>0.8.4</version>
</dependency>

Gradle

Add this snippet to your project's build.gradle dependencies section:

implementation 'one.util:streamex:0.8.4'

Pull requests are welcome.

Extension points exported contracts — how you extend this code

DoubleEmitter (Interface)
A helper interface to build a new stream by emitting elements and creating new emitters in a chain. Using this inte
src/main/java/one/util/streamex/DoubleStreamEx.java
Statement (Interface)
(no doc)
src/test/java/one/util/streamex/TestHelpers.java
IntCollector (Interface)
A Collector specialized to work with primitive int. @author Tagir Valeev @param the mutable accumu
src/main/java/one/util/streamex/IntCollector.java
Emitter (Interface)
A helper interface to build a new stream by emitting elements and creating new emitters in a chain. Using this inte
src/main/java/one/util/streamex/StreamEx.java
DoubleCollector (Interface)
A Collector specialized to work with primitive double. @author Tagir Valeev @param the mutable acc
src/main/java/one/util/streamex/DoubleCollector.java
IntEmitter (Interface)
A helper interface to build a new stream by emitting elements and creating new emitters in a chain. Using this inte
src/main/java/one/util/streamex/IntStreamEx.java

Core symbols most depended-on inside this repo

get
called by 656
src/test/java/one/util/streamex/api/MoreCollectorsTest.java
toArray
called by 480
src/main/java/one/util/streamex/IntCollector.java
range
called by 443
src/main/java/one/util/streamex/IntStreamEx.java
toList
called by 415
src/main/java/one/util/streamex/AbstractStreamEx.java
of
called by 363
src/main/java/one/util/streamex/StreamEx.java
parallel
called by 331
src/main/java/one/util/streamex/IntStreamEx.java
spliterator
called by 244
src/main/java/one/util/streamex/StreamEx.java
boxed
called by 218
src/main/java/one/util/streamex/IntStreamEx.java

Shape

Method 1,860
Class 174
Interface 16
Enum 1

Languages

Java100%

Modules by API surface

src/test/java/one/util/streamex/api/StreamExTest.java164 symbols
src/main/java/one/util/streamex/Internals.java151 symbols
src/main/java/one/util/streamex/IntStreamEx.java111 symbols
src/main/java/one/util/streamex/LongStreamEx.java96 symbols
src/main/java/one/util/streamex/DoubleStreamEx.java91 symbols
src/main/java/one/util/streamex/AbstractStreamEx.java89 symbols
src/main/java/one/util/streamex/StreamEx.java77 symbols
src/main/java/one/util/streamex/EntryStream.java70 symbols
src/main/java/one/util/streamex/PrefixOps.java64 symbols
src/test/java/one/util/streamex/api/EntryStreamTest.java60 symbols
src/test/java/one/util/streamex/api/MoreCollectorsTest.java53 symbols
src/test/java/one/util/streamex/api/IntStreamExTest.java51 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add streamex \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page