helper.ecal 854 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. copyMap copies a given map.
  3. */
  4. func copyMap(m, base={}) {
  5. let ret := base
  6. for [k, v] in m {
  7. ret[k] := v
  8. }
  9. return ret
  10. }
  11. /*
  12. max returns the maximum of two numbers.
  13. */
  14. func max(a, b) {
  15. if a > b {
  16. return a
  17. }
  18. return b
  19. }
  20. /*
  21. allNodeKeys returns the keys of all nodes of a certain kind.
  22. */
  23. func allNodeKeys(part, kind) {
  24. let ret := []
  25. let res := db.graphQL("main", "{ {{kind}} { key } }", {"kind" : kind})
  26. if len(res.data[kind]) > 0 {
  27. for o in res.data[kind] {
  28. ret := add(ret, o.key)
  29. }
  30. }
  31. return ret
  32. }
  33. /*
  34. Create a new list from a given list with all elements that pass
  35. the test implemented by the provided function.
  36. */
  37. func filter(list, f) {
  38. ret := []
  39. for i in list {
  40. if f(i) {
  41. ret := add(ret, i)
  42. }
  43. }
  44. return ret
  45. }