Sha256: a5408f8f1096799f17162536d6db5dc9a4c8739439e7ac4b058309a432da37a6
Contents?: true
Size: 751 Bytes
Versions: 2
Compression:
Stored size: 751 Bytes
Contents
module Transproc register(:map_array) do |array, *fns| Transproc(:map_array!, *fns)[Array[*array]] end register(:map_array!) do |array, *fns| fn = fns.size == 1 ? fns[0] : fns.reduce(:+) array.map! { |value| fn[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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
transproc-0.1.2 | lib/transproc/array.rb |
transproc-0.1.1 | lib/transproc/array.rb |