Switch.yqls 1.8 KB

123456789101112131415161718192021222324252627282930313233
  1. (
  2. #comment
  3. (let config (DataSource 'config))
  4. (let res_sink (DataSink 'result))
  5. (let list (AsList (String 'aaa) (String 'bbb) (String 'ccc)))
  6. (let id (lambda '(x) x))
  7. # id
  8. (let world (Write! world res_sink (Key) (Collect (Switch (Iterator list (DependsOn (String 'A))) '1 '('0) id)) '('('type))))
  9. # clone
  10. (let world (Write! world res_sink (Key) (Collect (Switch (Iterator list (DependsOn (String 'B))) '1 '('0) id '('0) id)) '('('type))))
  11. # separate
  12. (let tupleType (TupleType (DataType 'String) (DataType 'String)))
  13. (let vt (VariantType tupleType))
  14. (let vlist (AsList (Variant (String 'aaa) '0 vt) (Variant (String 'bbb) '1 vt) (Variant (String 'ccc) '0 vt)))
  15. (let handlerSplit1 (lambda '(x) (Map x (lambda '(s) (Concat (String '"#0: ") s)))))
  16. (let handlerSplit2 (lambda '(x) (Map x (lambda '(s) (Concat (String '"#1: ") s)))))
  17. (let world (Write! world res_sink (Key) (Collect (Switch (Iterator vlist (DependsOn (String 'D))) '1 '('1) handlerSplit2 '('0) handlerSplit1)) '('('type))))
  18. # reunion
  19. (let world (Write! world res_sink (Key) (Collect (Switch (Iterator vlist (DependsOn (String 'E))) '1 '('0 '1) id)) '('('type))))
  20. # reunion and parts
  21. (let world (Write! world res_sink (Key) (Collect (Switch (Iterator vlist (DependsOn (String 'F))) '1 '('0 '1) id '('1) handlerSplit2 '('0) handlerSplit1)) '('('type))))
  22. # multiple outputs
  23. (let twice (lambda '(x) (FlatMap x (lambda '(s) (AsList
  24. (Variant (Concat (String '"#0: ") s) '0 vt)
  25. (Variant (Concat (String '"#1: ") s) '1 vt)
  26. )))))
  27. (let world (Write! world res_sink (Key) (Collect (Switch (Iterator list (DependsOn (String 'G))) '1 '('0) twice)) '('('type))))
  28. # split and multiple outputs
  29. (let world (Write! world res_sink (Key) (Collect (Switch (Iterator list (DependsOn (String 'H))) '1 '('0) twice '('0) twice)) '('('type))))
  30. (let world (Commit! world res_sink))
  31. (return world)
  32. )