Sha256: 2fab82660c35b4fb2414048294709f29fa2846afbc0a68d73ededcb49ad87af8
Contents?: true
Size: 710 Bytes
Versions: 1
Compression:
Stored size: 710 Bytes
Contents
module Transproc register(:map_array) do |array, *fns| Transproc(:map_array!, *fns)[array.dup] end register(:map_array!) do |array, *fns| array.map! { |value| fns.reduce(:+)[value] } end register(:wrap) do |array, key, keys| Transproc(:map_array, Transproc(:nest, key, keys))[array] end register(:group) do |array, key, keys| names = nil array .group_by { |hash| names ||= hash.keys - keys Hash[names.zip(hash.values_at(*names))] } .map { |root, children| children.map! { |child| Hash[keys.zip(child.values_at(*keys))] } children.select! { |child| child.values.any? } root.merge(key => children) } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
transproc-0.1.0 | lib/transproc/array.rb |