GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tinyield/sek: Sek is a Java wrapper for Kotlin's Sequence. It allows the use of Kotlin's Sequence operations in Java without losing pipeline fluency.

BranchesTags
Open more actions menu

Latest commit

 

History

24 Commits
24 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

Repository files navigation

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

About

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

Topics

fluencyjavakotlinsequence

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

7 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.