Skip to content

Commit 448baae

Browse files
committed
Add forEach(iterate) and forEachRight(iterate) methods for lodash, math
and string plugins.
1 parent 6492d81 commit 448baae

File tree

6 files changed

+48
-0
lines changed
  • lodash-plugin/src
  • math-plugin/src
  • string-plugin/src

6 files changed

+48
-0
lines changed

lodash-plugin/src/main/java/com/github/underscore/lodash/$.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ public Chain<T> tap(final Block<T> func) {
229229
return new Chain<T>(value());
230230
}
231231

232+
public Chain<T> forEach(final Block<T> func) {
233+
$.forEach(value(), func);
234+
return new Chain<T>(value());
235+
}
236+
237+
public Chain<T> forEachRight(final Block<T> func) {
238+
$.forEachRight(value(), func);
239+
return new Chain<T>(value());
240+
}
241+
232242
public Chain<Boolean> every(final Predicate<T> pred) {
233243
return new Chain<Boolean>($.every(value(), pred));
234244
}

lodash-plugin/src/test/java/com/github/underscore/lodash/LodashTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,12 @@ public void chain() {
656656
$.chain(new String[] {""}).tap(new Block<String>() {
657657
public void apply(String str) {
658658
} });
659+
$.chain(new String[] {""}).forEach(new Block<String>() {
660+
public void apply(String str) {
661+
} });
662+
$.chain(new String[] {""}).forEachRight(new Block<String>() {
663+
public void apply(String str) {
664+
} });
659665
$.chain(new String[] {""}).every(new Predicate<String>() {
660666
public Boolean apply(String str) { return true; } });
661667
$.chain(new String[] {""}).some(new Predicate<String>() {

math-plugin/src/main/java/com/github/underscore/math/$.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ public Chain<T> tap(final Block<T> func) {
183183
return new Chain<T>(value());
184184
}
185185

186+
public Chain<T> forEach(final Block<T> func) {
187+
$.forEach(value(), func);
188+
return new Chain<T>(value());
189+
}
190+
191+
public Chain<T> forEachRight(final Block<T> func) {
192+
$.forEachRight(value(), func);
193+
return new Chain<T>(value());
194+
}
195+
186196
public Chain<Boolean> every(final Predicate<T> pred) {
187197
return new Chain<Boolean>($.every(value(), pred));
188198
}

math-plugin/src/test/java/com/github/underscore/math/MathTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ public void chain() {
288288
$.chain(new String[] {""}).tap(new Block<String>() {
289289
public void apply(String str) {
290290
} });
291+
$.chain(new String[] {""}).forEach(new Block<String>() {
292+
public void apply(String str) {
293+
} });
294+
$.chain(new String[] {""}).forEachRight(new Block<String>() {
295+
public void apply(String str) {
296+
} });
291297
$.chain(new String[] {""}).every(new Predicate<String>() {
292298
public Boolean apply(String str) { return true; } });
293299
$.chain(new String[] {""}).some(new Predicate<String>() {

string-plugin/src/main/java/com/github/underscore/string/$.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ public Chain<T> tap(final Block<T> func) {
220220
return new Chain<T>(value());
221221
}
222222

223+
public Chain<T> forEach(final Block<T> func) {
224+
$.forEach(value(), func);
225+
return new Chain<T>(value());
226+
}
227+
228+
public Chain<T> forEachRight(final Block<T> func) {
229+
$.forEachRight(value(), func);
230+
return new Chain<T>(value());
231+
}
232+
223233
public Chain<Boolean> every(final Predicate<T> pred) {
224234
return new Chain<Boolean>($.every(value(), pred));
225235
}

string-plugin/src/test/java/com/github/underscore/string/StringTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,12 @@ public void chain() {
19931993
$.chain(new String[] {""}).tap(new Block<String>() {
19941994
public void apply(String str) {
19951995
} });
1996+
$.chain(new String[] {""}).forEach(new Block<String>() {
1997+
public void apply(String str) {
1998+
} });
1999+
$.chain(new String[] {""}).forEachRight(new Block<String>() {
2000+
public void apply(String str) {
2001+
} });
19962002
$.chain(new String[] {""}).every(new Predicate<String>() {
19972003
public Boolean apply(String str) { return true; } });
19982004
$.chain(new String[] {""}).some(new Predicate<String>() {

0 commit comments

Comments
 (0)