/enumerable4j

Amazing Ruby's "Enumerable" ported to Java

Primary LanguageJavaMIT LicenseMIT

Maven Javadocs License: MIT Commit activity Hits-of-Code

CI 0pdd Dependency Status Known Vulnerabilities

DevOps By Rultor.com EO badge We recommend IntelliJ IDEA

Qulice Maintainability Rating Codebeat Badge Codacy Badge Codecov

Overview

enumerable4j is a Ruby's well known Enumerable ported to java.

How to use

Get the latest version here:

<dependency>
  <groupId>io.github.dgroup</groupId>
  <artifactId>enumerable4j</artifactId>
  <version>${version}</version>
</dependency>

Java version required: 1.8+.

enumerable4j (MIT) Java 8 cactoos (MIT) eclipse-collections (EDL)
.all(...) .stream().allMatch(...); new And<>(...,...).value() tbd
.any(...) .stream().anyMatch(...); new Or<>(...,...).value() tbd
.none(...) .stream().noneMatch(...); new And<>(...,...).value() tbd
.select(...) .stream().filter(...).collect(Collectors.toList()) new Filtered<>(...,...) tbd
.count(...) .stream().filter(...).count() - tbd

.all

Collection<Integer> src = new EnumerableOf<>(1, 2, 3);
boolean allPositive = src.all(v -> v > 0); // true 

.any

Collection<Integer> src = new EnumerableOf<>(-1, 0, 1);
boolean oneIsPositive = src.any(v -> v > 0); // true 

.none

Collection<Integer> src = new EnumerableOf<>(-2, -1, 0);
boolean noneIsPositive = src.none(v -> v > 0); // true 

.select

Collection<Integer> src = new EnumerableOf<>(-1, 1, 2);
Collection<Integer> positive = src.select(v -> v > 0); // [1, 2] 

.map

Collection<Integer> src = new EnumerableOf<>(0, 1, 2);
Collection<Integer> positive = src.map(v -> v + 1); // [1, 2, 3] 

.count

Collection<Integer> src = new EnumerableOf<>(-1, 0, 1, 2);
long countNegative = src.count(val -> val < 0); // 1 
long count = src.count(null); // 4

How to contribute?

EO badge

  1. Pull requests are welcome! Don't forget to add your name to contribution section and run this, beforehand:
    mvn -Pqulice clean install
  2. Everyone interacting in this project’s codebases, issue trackers, chat rooms is expected to follow the code of conduct.
  3. Latest maven coordinates here:
    <dependency>
        <groupId>io.github.dgroup</groupId>
        <artifactId>enumerable4j</artifactId>
        <version>${version}</version>
    </dependency>

Contributors