Skip to content

Commit

Permalink
Add selectValue method
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 committed Feb 20, 2024
1 parent 6c4e54f commit 8d06ec3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
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/[email protected].5
uses: bakdata/ci-templates/.github/workflows/[email protected].6
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/[email protected].5
uses: bakdata/ci-templates/.github/workflows/[email protected].6
with:
java-version: 17
release-type: "${{ inputs.release-type }}"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
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

0 comments on commit 8d06ec3

Please sign in to comment.