Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selectValue method #16

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build-and-publish:
name: Java Gradle
uses: bakdata/ci-templates/.github/workflows/java-gradle-library.yaml@1.40.6
uses: bakdata/ci-templates/.github/workflows/java-gradle-library.yaml@1.41.0
with:
java-version: 17
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
jobs:
java-gradle-release:
name: Java Gradle
uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.40.6
uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.41.0
with:
java-version: 17
release-type: "${{ inputs.release-type }}"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
`java-library`
id("net.researchgate.release") version "3.0.2"
id("com.bakdata.sonar") version "1.1.17"
id("com.bakdata.sonatype") version "1.1.14"
id("com.bakdata.sonatype") version "1.2.1"
id("org.hildan.github.changelog") version "2.2.0"
id("io.freefair.lombok") version "8.4"
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/bakdata/util/seq2/Seq2.java
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,15 @@ default <K> PairSeq<K, T> selectKey(final Function<? super T, ? extends K> keyMa
return this.mapToPair(keyMapper, Function.identity());
}

/**
* Map a {@code Seq2} to a {@code PairSeq}
*
* @see Seq#map(Function)
*/
default <V> PairSeq<T, V> selectValue(final Function<? super T, ? extends V> valueMapper) {
return this.mapToPair(Function.identity(), valueMapper);
}

@Override
default Seq2<T> sequential() {
return seq(this.toSeq().sequential());
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/com/bakdata/util/seq2/Seq2Test.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -67,6 +67,14 @@ void shouldSelectKey() {
.containsExactlyInAnyOrder(new Tuple2<>(2, 1), new Tuple2<>(3, 2));
}

@Test
void shouldSelectValue() {
assertThat((Stream<Tuple2<Integer, Integer>>) 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<Tuple2<Integer, Integer>>) Seq2.seq(List.of(1, 2))
Expand Down
Loading