Sek - A Java wrapper for Kotlin's Sequence

Sek is a Java wrapper for Kotlin's Sequence. It allows the use of Kotlin's Sequence operations in Java without losing pipeline fluency.

License

License

GroupId

GroupId

com.tinyield
ArtifactId

ArtifactId

sek
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Sek - A Java wrapper for Kotlin's Sequence
Sek is a Java wrapper for Kotlin's Sequence. It allows the use of Kotlin's Sequence operations in Java without losing pipeline fluency.
Project URL

Project URL

https://github.com/tinyield/sek
Source Code Management

Source Code Management

https://github.com/tinyield/sek.git

Download sek

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.4.21

test (2)

Group / Artifact Type Version
org.testng : testng jar 6.9.10
org.assertj : assertj-core jar 3.16.1

Project Modules

There are no modules declared in this project.

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

com.tinyield

TINYield

Towards sequence traversal optimization and extensibility

Versions

Version
1.0.1
1.0.0