Git Product home page Git Product logo

sek's Introduction

Sek

Quality Gate Status Coverage Maven Central

Sek is a Java wrapper for Kotlin's Sequence.

With Sek you can use the full suite of operations that Kotlin's Sequence provide without leaving the Java ecosystem, on top of outperforming Java's Stream in sequential processing operations in a variety of use-cases.

Installation

This project can be installed into yours by adding a maven dependency, like so:

<dependency>
    <groupId>com.tinyield</groupId>
    <artifactId>sek</artifactId>
    <version>1.0.0</version>
</dependency>

If you would prefer not to add a dependency to this project, you can also just copy the Sek.java file to your project. You will however need to add Kotlin to your project's dependencies, so if you're using maven:

<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-stdlib</artifactId>
    <version>${kotlin.version}</version>
</dependency>

For more information check Kotlin's official page on using maven here.

Usage

Create a Sek using of, generate or the empty method and then chain operations into the pipeline until you call a terminal operation like forEach or reduce. For the full list of supported methods check Sek.java or the official Kotlin documentation about Sequence.

Sek<String> songs = Sek.of(
        new Song("505", "Alternative"),
        new Song("Amsterdam", "Alternative"),
        new Song("Mural","Hip-Hop")
)
.filterNot(song -> song.name().startsWith("A"))
.map(Song::name);

Sek<String> artists = Sek.of(
    new Artist("Arctic Monkeys", "band"),
    new Artist("Nothing But Thieves", "band"),
    new Artist("Lupe Fiasco", "solo-artist")
)
.distinctBy(Artist::type)
.map(Artist::name);

songs.zip(artists, (song, artist) -> String.format("%s by %s", song, artist))
     .forEach(System.out::println);

// Output
// 505 by Arctic Monkeys
// Mural by Lupe Fiasco

You can also add user-defined operations to your pipeline by using the then method, even using Kotlin's extension methods. Let's say you have a Extensions.kt file with the following definition:

fun <T> Sequence<T>.oddIndexes() = sequence<T> {
    var isOdd = false
    for (item in this@oddIndexes) {
        if(isOdd) yield(item)
        isOdd = !isOdd
    }
}

You could use it with Sek like this:

 Sek.of("a", "b", "c", "d", "f", "e")
    .then(Extensionskt::oddIndexes)
    .forEach(out::println)

// Output
// b
// d
// e

License

This project is licensed under Apache License, version 2.0

sek's People

Contributors

dpoeira91 avatar fmcarvalho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sek's Issues

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.