Skip to content

Commit

Permalink
Fix distinct return type to allow list operation chaining (finos#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugohills-regnosys authored Mar 4, 2022
1 parent 478affd commit eee8677
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static <T> ComparisonResult disjoint(Mapper<T> o1, Mapper<T> o2) {

// distinct

public static <T> Mapper<T> distinct(Mapper<T> o) {
public static <T> MapperC<T> distinct(Mapper<T> o) {
return MapperC.of(o.getMulti()
.stream()
.distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3605,6 +3605,29 @@ class ListOperationTest {
assertEquals(ImmutableList.of(1, 2, 3, 4), res);
}

@Test
def void shouldGenerateDistinctIntListSort() {
val model = '''
func FuncFoo:
inputs:
numbers int (0..*)
output:
sortedNumbers int (0..*)
set sortedNumbers:
numbers
distinct
sort
'''
val code = model.generateCode
val classes = code.compileToClasses
val func = classes.createFunc("FuncFoo");

val res = func.invokeFunc(List, ImmutableList.of(4, 2, 2, 4, 3, 1, 1, 3))
assertEquals(4, res.size);
assertEquals(ImmutableList.of(1, 2, 3, 4), res);
}

@Test
def void shouldGenerateDateListSort() {
val model = '''
Expand Down

0 comments on commit eee8677

Please sign in to comment.