Skip to content

Instantly share code, notes, and snippets.

@christopherzimmerman
Last active July 2, 2020 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopherzimmerman/e26262ecd0c973cb637a1d73fe7235f5 to your computer and use it in GitHub Desktop.
Save christopherzimmerman/e26262ecd0c973cb637a1d73fe7235f5 to your computer and use it in GitHub Desktop.
agg.cr
n = NamedTuple.new(
foo: [1, 2, 34, 4],
bar: [32,4, 2, 1, 4],
)
macro agg(nt, **fns)
NamedTuple.new(
{% for k, v in fns %}
{{k}}: {{nt}}[{{k.symbolize}}].{{v.id}},
{% end %}
)
end
f = agg(n, foo: :max, bar: :sum)
puts f
# {foo: 34, bar: 43}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment