runtime_apply_quoted_code.sql 684 B

123456789101112131415161718192021
  1. /* syntax version 1 */
  2. /* postgres can not */
  3. $func = ($x)->{
  4. return $x == 1;
  5. };
  6. $structApply = ($strValue, $f)->{
  7. $code = EvaluateCode(LambdaCode(($strCode)->{
  8. $members = StructTypeComponents(TypeHandle(TypeOf($strValue)));
  9. return Yql::Fold($members, ReprCode(false), ($item, $state)->{
  10. $member = FuncCode("Member", $strCode, AtomCode($item.Name));
  11. $apply = FuncCode("Apply", QuoteCode($f), $member);
  12. return FuncCode("Or", $state, $apply);
  13. });
  14. }));
  15. return $code($strValue);
  16. };
  17. select $structApply(AsStruct(1 as a,2 as b,3 as c), $func);
  18. select $structApply(AsStruct(4 as a,2 as b,3 as c), $func);