fp.tin 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #function {filter} {
  2. #local table {%1};
  3. #local cond {%2};
  4. #replace {cond} {KEY} {$$key};
  5. #replace {cond} {VALUE} {$$value};
  6. #local newTable {};
  7. #local key {};
  8. #foreach {*table[]} {key} {
  9. #local value {$table[$key]};
  10. #line sub var #if { $cond } {
  11. #cat newTable {{$key}{$value}};
  12. };
  13. };
  14. #return {$newTable}
  15. };
  16. #function {filterMap} {
  17. #local table {%1};
  18. #local cond {%2};
  19. #local body {%3};
  20. #replace {cond} {KEY} {$$key};
  21. #replace {cond} {VALUE} {$$value};
  22. #replace {body} {KEY} {$$key};
  23. #replace {body} {VALUE} {$$value};
  24. #local newTable {};
  25. #local key {};
  26. #foreach {*table[]} {key} {
  27. #local value {$table[$key]};
  28. #line sub var #if { $cond } {
  29. #cat newTable {{$key}{$body}};
  30. };
  31. };
  32. #return {$newTable}
  33. };
  34. #function {mapIf} {
  35. #local table {%1};
  36. #local cond {%2};
  37. #local body {%3};
  38. #replace {cond} {KEY} {$$key};
  39. #replace {cond} {VALUE} {$$value};
  40. #replace {body} {KEY} {$$key};
  41. #replace {body} {VALUE} {$$value};
  42. #local newTable {};
  43. #local key {};
  44. #foreach {*table[]} {key} {
  45. #local value {$table[$key]};
  46. #line sub var {
  47. #if { $cond } {
  48. #cat newTable {{$key}{$body}};
  49. };
  50. #else {
  51. #cat newTable {{$key}{$value}};
  52. };
  53. };
  54. };
  55. #return {$newTable}
  56. };
  57. #function {map} {
  58. #local table {%1};
  59. #local body {%2};
  60. #replace {body} {KEY} {$$key};
  61. #replace {body} {VALUE} {$$value};
  62. #local newTable {};
  63. #local key {};
  64. #foreach {*table[]} {key} {
  65. #local value {$table[$key]};
  66. #cat newTable {{$key}{$body}};
  67. };
  68. #return {$newTable}
  69. };