Skip to content

Commit

Permalink
Merge pull request #23 from fink-lang/fix-flat-map
Browse files Browse the repository at this point in the history
fix(map): fix flap map handling
  • Loading branch information
kollhof authored Mar 29, 2020
2 parents ea01c04 + 116e327 commit 3371d07
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lang/iterable/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ export const transform_any = (flatten)=> (node, {transform, unique_ident})=> {
const [item] = params([item_param]);
const [expressions, last_expr] = split_last(node.exprs);

const last_is_spread = (last_expr.type === 'spread');

const yield_value = (
last_expr.type === 'spread'
last_is_spread
? last_expr.right
: last_expr
);

if (last_expr.type === 'spread') {
flatten = true;
}

const items = unique_ident('items');

return generator('map')(items)(
for_of(item, items)(
...expressions.map(block_statement({transform})),
...yield_or_stop(transform(yield_value), unique_ident, flatten)
...yield_or_stop(
transform(yield_value),
unique_ident, flatten || last_is_spread
)
)
);
};
Expand Down

0 comments on commit 3371d07

Please sign in to comment.