Skip to content

Commit

Permalink
Add flatMap method to __core__.iter
Browse files Browse the repository at this point in the history
  • Loading branch information
bamless committed Jun 25, 2024
1 parent 270933f commit ea2be7d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/jstar/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(JSTAR_VERSION_MAJOR * 100000 + JSTAR_VERSION_MINOR * 1000 + JSTAR_VERSION_PATCH)

// compiler and platform on which this J* binary was compiled
#define JSTAR_COMPILER "GNU 13.2.1"
#define JSTAR_COMPILER "GNU 14.1.1"
#define JSTAR_PLATFORM "Linux"

// Options
Expand Down
Binary file modified src/lib/core/iter.jsc
Binary file not shown.
17 changes: 17 additions & 0 deletions src/lib/core/iter.jsr
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class Iterable
return map(this, fn)
end

fun flatMap(fn)
return flatMap(this, fn)
end

fun filter(predicate)
return filter(this, predicate)
end
Expand Down Expand Up @@ -490,6 +494,19 @@ fun map(iterable, fn)
end
end

fun flatMap(iterable, fn)
for var e in iterable
var res = fn(e)
if res is Iterable
for var e in res
yield e
end
else
yield e
end
end
end

fun filter(iterable, predicate)
for var e in iterable
if predicate(e)
Expand Down

0 comments on commit ea2be7d

Please sign in to comment.