Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit538b645

Browse files
committed
adding Tuple2/3/4/5#fill to fill each tuple instance with a given value
1 parent00a4a37 commit538b645

File tree

8 files changed

+68
-2
lines changed

8 files changed

+68
-2
lines changed

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple2.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public _2 _2() {
5757
* Destructure and apply this tuple to a function accepting the same number of arguments as this tuple's
5858
* slots. This can be thought of as a kind of dual to uncurrying a function and applying a tuple to it.
5959
*
60-
* @param fn the function to apply
61-
* @param <R>the return type of the function
60+
* @param fnthe function to apply
61+
* @param <R> the return type of the function
6262
* @return the result of applying the destructured tuple to the function
6363
*/
6464
public <R>Rinto(BiFunction<?super_1, ?super_2, ?extendsR>fn) {
@@ -115,4 +115,14 @@ public static <K, V> Tuple2<K, V> fromEntry(Map.Entry<K, V> entry) {
115115
returnnewTuple2<>(entry.getKey(),singletonHList(entry.getValue()));
116116
}
117117

118+
/**
119+
* Given a value of type <code>A</code>, produced an instance of this tuple with each slot set to that value.
120+
*
121+
* @param a the value to fill the tuple with
122+
* @param <A> the value type
123+
* @return the filled tuple
124+
*/
125+
publicstatic <A>Tuple2<A,A>fill(Aa) {
126+
returntuple(a,a);
127+
}
118128
}

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple3.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,16 @@ public <_2Prime, _3Prime> Tuple3<_1, _2Prime, _3Prime> biMap(Function<? super _2
9898
Function<?super_3, ?extends_3Prime>rFn) {
9999
returnnewTuple3<>(_1(),tail().biMap(lFn,rFn));
100100
}
101+
102+
/**
103+
* Given a value of type <code>A</code>, produced an instance of this tuple with each slot set to that value.
104+
*
105+
* @param a the value to fill the tuple with
106+
* @param <A> the value type
107+
* @return the filled tuple
108+
* @see Tuple2#fill
109+
*/
110+
publicstatic <A>Tuple3<A,A,A>fill(Aa) {
111+
returntuple(a,a,a);
112+
}
101113
}

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple4.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,16 @@ public <_3Prime, _4Prime> Tuple4<_1, _2, _3Prime, _4Prime> biMap(Function<? supe
110110
Function<?super_4, ?extends_4Prime>rFn) {
111111
returnnewTuple4<>(_1(),tail().biMap(lFn,rFn));
112112
}
113+
114+
/**
115+
* Given a value of type <code>A</code>, produced an instance of this tuple with each slot set to that value.
116+
*
117+
* @param a the value to fill the tuple with
118+
* @param <A> the value type
119+
* @return the filled tuple
120+
* @see Tuple2#fill
121+
*/
122+
publicstatic <A>Tuple4<A,A,A,A>fill(Aa) {
123+
returntuple(a,a,a,a);
124+
}
113125
}

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple5.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,16 @@ public <_4Prime, _5Prime> Tuple5<_1, _2, _3, _4Prime, _5Prime> biMap(Function<?
108108
Function<?super_5, ?extends_5Prime>rFn) {
109109
returnnewTuple5<>(_1(),tail().biMap(lFn,rFn));
110110
}
111+
112+
/**
113+
* Given a value of type <code>A</code>, produced an instance of this tuple with each slot set to that value.
114+
*
115+
* @param a the value to fill the tuple with
116+
* @param <A> the value type
117+
* @return the filled tuple
118+
* @see Tuple2#fill
119+
*/
120+
publicstatic <A>Tuple5<A,A,A,A,A>fill(Aa) {
121+
returntuple(a,a,a,a,a);
122+
}
111123
}

‎src/test/java/com/jnape/palatable/lambda/adt/hlist/Tuple2Test.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public void into() {
6161
assertEquals("foo1",tuple.into((s,i) ->s +i));
6262
}
6363

64+
@Test
65+
publicvoidfill() {
66+
assertEquals(tuple("foo","foo"),Tuple2.fill("foo"));
67+
}
68+
6469
@Test
6570
publicvoidfunctorProperties() {
6671
assertEquals(newTuple2<>(1,newSingletonHList<>("2")),tuple2.fmap(Object::toString));

‎src/test/java/com/jnape/palatable/lambda/adt/hlist/Tuple3Test.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public void into() {
6060
assertEquals("foo12.0",tuple.into((s,i,d) ->s +i +d));
6161
}
6262

63+
@Test
64+
publicvoidfill() {
65+
assertEquals(tuple("foo","foo","foo"),Tuple3.fill("foo"));
66+
}
67+
6368
@Test
6469
publicvoidfunctorProperties() {
6570
assertEquals(newTuple3<>(1,newTuple2<>("2",newSingletonHList<>("3"))),tuple3.fmap(Object::toString));

‎src/test/java/com/jnape/palatable/lambda/adt/hlist/Tuple4Test.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public void into() {
6363
assertEquals("foo12.0false",tuple.into((s,i,d,b) ->s +i +d +b));
6464
}
6565

66+
@Test
67+
publicvoidfill() {
68+
assertEquals(tuple("foo","foo","foo","foo"),Tuple4.fill("foo"));
69+
}
70+
6671
@Test
6772
publicvoidfunctorProperties() {
6873
assertEquals(newTuple4<>(1,newTuple3<>("2",newTuple2<>('3',newSingletonHList<>(true)))),tuple4.fmap(x -> !x));

‎src/test/java/com/jnape/palatable/lambda/adt/hlist/Tuple5Test.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public void randomAccess() {
6161
verifyNoMoreInteractions(spiedTail);
6262
}
6363

64+
@Test
65+
publicvoidfill() {
66+
assertEquals(tuple("foo","foo","foo","foo","foo"),Tuple5.fill("foo"));
67+
}
68+
6469
@Test
6570
publicvoidfunctorProperties() {
6671
assertEquals(newTuple5<>(1,newTuple4<>("2",newTuple3<>('3',newTuple2<>(false,newSingletonHList<>("5"))))),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp