Created
October 23, 2017 23:47
-
-
Save bcardiff/b6c8fff62a5812e476a57e90c21a51c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
struct NamedTuple | |
macro map_keys(tuple, properties) | |
{% begin %} | |
%tuple = {{tuple}} | |
NamedTuple.new( | |
{% for key, value in properties %} | |
{{value.id}}: %tuple[{{key.symbolize}}], | |
{% end %} | |
) | |
{% end %} | |
end | |
end | |
NamedTuple.map_keys({a: 1, b: "foo"}, {a: :qux, b: :bar}) # => {qux: 1, bar: "foo"} : NamedTuple(qux: Int32, bar: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment