MCPcopy Create free account
hub / github.com/PRQL/prql / extract_partial_application

Function extract_partial_application

prqlc/prqlc/src/semantic/resolver/functions.rs:399–463  ·  view source on GitHub ↗
(mut func: Box<Func>, position: usize)

Source from the content-addressed store, hash-verified

397}
398
399fn extract_partial_application(mut func: Box<Func>, position: usize) -> Box<Func> {
400 // Input:
401 // Func {
402 // params: [x, y, z],
403 // args: [
404 // x,
405 // Func {
406 // params: [a, b],
407 // args: [a],
408 // body: arg_body
409 // },
410 // z
411 // ],
412 // body: parent_body
413 // }
414
415 // Output:
416 // Func {
417 // params: [b],
418 // args: [],
419 // body: Func {
420 // params: [x, y, z],
421 // args: [
422 // x,
423 // Func {
424 // params: [a, b],
425 // args: [a, b],
426 // body: arg_body
427 // },
428 // z
429 // ],
430 // body: parent_body
431 // }
432 // }
433
434 // This is quite in-efficient, especially for long pipelines.
435 // Maybe it could be special-cased, for when the arg func has a single param.
436 // In that case, it may be possible to pull the arg func up and basically swap
437 // it with the parent func.
438
439 let arg = func.args.get_mut(position).unwrap();
440 let arg_func = arg.kind.as_func_mut().unwrap();
441
442 let param_name = format!("_partial_{}", arg.id.unwrap());
443 let substitute_arg = Expr::new(Ident::from_path(vec![
444 NS_PARAM.to_string(),
445 param_name.clone(),
446 ]));
447 arg_func.args.push(substitute_arg);
448
449 // set the arg func body to the parent func
450 Box::new(Func {
451 name_hint: None,
452 return_ty: None,
453 body: Box::new(Expr::new(ExprKind::Func(func))),
454 params: vec![FuncParam {
455 name: param_name,
456 ty: None,

Callers 1

resolve_function_argsMethod · 0.85

Calls 3

get_mutMethod · 0.80
pushMethod · 0.80
FuncClass · 0.50

Tested by

no test coverage detected