-
-
Save christopherzimmerman/e26262ecd0c973cb637a1d73fe7235f5 to your computer and use it in GitHub Desktop.
agg.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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