replace_member.sql 554 B

123456789101112131415161718192021222324252627
  1. /* postgres can not */
  2. /* syntax version 1 */
  3. $data = <|x: [<|y: 2|>], z: 5|>;
  4. -- set field function
  5. $F = ($field, $function) -> (
  6. ($struct) -> (
  7. ReplaceMember($struct, $field, $function($struct.$field))
  8. )
  9. );
  10. -- set list element function
  11. $E = ($index, $function) -> (
  12. ($list) -> (
  13. ListMap(ListEnumerate($list), ($pair) -> (
  14. IF ($pair.0 = $index, $function($pair.1), $pair.1)
  15. ))
  16. )
  17. );
  18. -- set value function
  19. $V = ($value) -> (
  20. ($_item) -> ($value)
  21. );
  22. SELECT $F("x", $E(0, $F("y", $V(3))))($data)