Git Product home page Git Product logo

xstream's Introduction

Stream

Implementation of simplified and modified version of Java Stream API with lazy evaluation.

Build Status codecov

Dependency

This project is distributed via JitPack. Register a JitPack repository at your pom.xml:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

And add the following dependency:

<dependency>
    <groupId>com.github.jolice</groupId>
    <artifactId>Stream</artifactId>
    <version>v1.0</version>
</dependency>

Creating a stream

StreamFactory class is responsible for creating streams.

A stream may be constructed from fixed list of elements:

Stream<String> stream = StreamFactory.of("alpha", "bravo", "charlie", "delta", "echo");

Or from any Iterable implementation:

List<String> list = Arrays.asList("alpha", "bravo", "charlie", "delta", "echo");
Stream<String> stream = StreamFactory.of(list);

Empty stream may be created as follows:

Stream<String> stream = StreamFactory.empty();

Infinite streams are also supported:

Stream<Integer> stream = StreamFactory.iterate(1, i -> i + 1).limit(5);

Operations

Operations inherited from Java 8 Stream interface

  • Iterator
  • Filter
  • Map
  • FlatMap
  • Distinct
  • Sorted
  • Peek
  • Limit
  • Skip
  • ForEach
  • ToArray
  • Reduce
  • Collect
  • Min
  • Max
  • Count
  • AnyMatch
  • AllMatch
  • NoneMatch
  • FindAny

Custom operations

TakeWhile skips all elements after the first one that doesn't match a predicate:

StreamFactory.of(1,2,3,4,5,6).takeWhile(x -> x <= 3)
       .collect(Collectors.toList()); // [1,2,3]

DropWhile skips all elements before the first one that matches a predicate:

 StreamFactory.of(6,5,4,3,2,1).dropWhile(x -> x > 3)
       .collect(Collectors.toList()); // [3,2,1]

FiterNot filters out the elements that match the predicate, inverse for Filter:

StreamFactory.of(1,2,3,4,5,6).filterNot(x -> x % 2 == 0)
        .collect(Collectors.toList()); // [1,3,5]

FilterNulls filters out null items:

StreamFactory.of(1, 2, null, 4, null, 6).filterNulls()
        .collect(Collectors.toList()); // [1, 2, 4, 6]

Not supported operations

  • Parallel
  • MapToInt / Double / Long
  • FlatMapToInt / Double / Long
  • ForEachOrdered

xstream's People

Contributors

jolice avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.