Skip to content

Commit

Permalink
Merge pull request #127 from fink-lang/imporve-pipe
Browse files Browse the repository at this point in the history
feat: improve pipes with partials by removing partial wrapper for callees
  • Loading branch information
kollhof authored Jul 20, 2021
2 parents 4b8de3a + 05e2e3a commit 560ccd9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 45 deletions.
49 changes: 16 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/lang/call/pipe.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ babel_types = import '@babel/types'
{assign, lets, undef, unique_ident} = import '../../js/types.fnk'
{wrap_with_comment_loc} = import '../comments/init.fnk'
{transform, map_with_ctx, collect_with_ctx} = import '../transform.fnk'
{transform_with_partial} = import '../partial/init.fnk'



transform_callee = fn result: fn expr, ctx:
[callee, next_ctx] = transform expr, ctx
transform_pipe_step = fn result: fn expr, ctx:
callee_ctx = {...ctx, partial_ident: result}

js = wrap_with_comment_loc
assign result, callExpression callee, [result]
expr
[is_partial, callee, {partial_ident: _, ...next_ctx}] = transform_with_partial expr, callee_ctx, false

step = match is_partial:
false:
assign result, callExpression callee, [result]
else:
assign result, callee

js = wrap_with_comment_loc step, expr
[js, next_ctx]


Expand All @@ -32,7 +38,7 @@ transform_pipe = fn node, ctx:
[result, pipe_ctx] = unique_ident 'pipe_result', id_ctx

[pipe_calls, next_ctx] = pipe exprs:
map_with_ctx transform_callee result
map_with_ctx transform_pipe_step result
collect_with_ctx pipe_ctx

js = doExpression
Expand Down
9 changes: 3 additions & 6 deletions src/lang/call/pipe.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ exports[`pipe compiles 1`] = `
"{
let ˆpipe_result_1 = undefined;
ˆpipe_result_1 = foopipe_result_1);
ˆpipe_result_1 =partial => barpartial, {
ˆpipe_result_1 = barpipe_result_1, {
foo
}))(ˆpipe_result_1);
});
ˆpipe_result_1 = spampipe_result_1);
ˆpipe_result_1 =partial => [...ˆpartial])(ˆpipe_result_1);
ˆpipe_result_1 = [...ˆpipe_result_1];
}
{
let ˆpipe_result_2 = [1, 2, 3];
Expand Down

0 comments on commit 560ccd9

Please sign in to comment.