From 8d06ec3cb5f96f4198eb9d4a50ae28f177dad62c Mon Sep 17 00:00:00 2001 From: Philipp Schirmer Date: Tue, 20 Feb 2024 16:22:33 +0100 Subject: [PATCH] Add selectValue method --- .github/workflows/build-and-publish.yaml | 2 +- .github/workflows/release.yaml | 2 +- build.gradle.kts | 4 ++-- src/main/java/com/bakdata/util/seq2/Seq2.java | 9 +++++++++ src/test/java/com/bakdata/util/seq2/Seq2Test.java | 10 +++++++++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml index 6f0ea26..2674794 100644 --- a/.github/workflows/build-and-publish.yaml +++ b/.github/workflows/build-and-publish.yaml @@ -8,7 +8,7 @@ on: jobs: build-and-publish: name: Java Gradle - uses: bakdata/ci-templates/.github/workflows/java-gradle-library.yaml@1.40.5 + uses: bakdata/ci-templates/.github/workflows/java-gradle-library.yaml@1.40.6 with: java-version: 17 secrets: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b139422..6a30c40 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,7 +16,7 @@ on: jobs: java-gradle-release: name: Java Gradle - uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.40.5 + uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.40.6 with: java-version: 17 release-type: "${{ inputs.release-type }}" diff --git a/build.gradle.kts b/build.gradle.kts index 86849e9..147f8ba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,8 +4,8 @@ description = "This library is an extension to the great jOOλ library" plugins { `java-library` id("net.researchgate.release") version "3.0.2" - id("com.bakdata.sonar") version "1.1.9" - id("com.bakdata.sonatype") version "1.1.9" + id("com.bakdata.sonar") version "1.1.14" + id("com.bakdata.sonatype") version "1.1.14" id("org.hildan.github.changelog") version "1.12.1" id("io.freefair.lombok") version "6.6.3" } diff --git a/src/main/java/com/bakdata/util/seq2/Seq2.java b/src/main/java/com/bakdata/util/seq2/Seq2.java index 090a0ef..80b2b05 100644 --- a/src/main/java/com/bakdata/util/seq2/Seq2.java +++ b/src/main/java/com/bakdata/util/seq2/Seq2.java @@ -1064,6 +1064,15 @@ default PairSeq selectKey(final Function keyMa return this.mapToPair(keyMapper, Function.identity()); } + /** + * Map a {@code Seq2} to a {@code PairSeq} + * + * @see Seq#map(Function) + */ + default PairSeq selectValue(final Function valueMapper) { + return this.mapToPair(Function.identity(), valueMapper); + } + @Override default Seq2 sequential() { return seq(this.toSeq().sequential()); diff --git a/src/test/java/com/bakdata/util/seq2/Seq2Test.java b/src/test/java/com/bakdata/util/seq2/Seq2Test.java index fe2f2e3..ea10fce 100644 --- a/src/test/java/com/bakdata/util/seq2/Seq2Test.java +++ b/src/test/java/com/bakdata/util/seq2/Seq2Test.java @@ -1,5 +1,5 @@ /* - * Copyright (c), 2023 bakdata GmbH + * Copyright (c), 2024 bakdata GmbH * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -67,6 +67,14 @@ void shouldSelectKey() { .containsExactlyInAnyOrder(new Tuple2<>(2, 1), new Tuple2<>(3, 2)); } + @Test + void shouldSelectValue() { + assertThat((Stream>) Seq2.seq(List.of(1, 2)) + .selectValue(i -> i + 1)) + .hasSize(2) + .containsExactlyInAnyOrder(new Tuple2<>(1, 2), new Tuple2<>(2, 3)); + } + @Test void shouldFlatMapToOptionalPair() { assertThat((Stream>) Seq2.seq(List.of(1, 2))