Module: Rupture::Map
Instance Method Summary collapse
- #assoc(*kvs) ⇒ Object
- #associate(*kvs) ⇒ Object
- #destruct(*keys) ⇒ Object
- #into(other) ⇒ Object
- #map? ⇒ Boolean
- #update(key, fn = nil, *args, &block) ⇒ Object
- #update_each(keys, *args, &block) ⇒ Object
Instance Method Details
#assoc(*kvs) ⇒ Object
11 12 13 |
# File 'lib/rupture/map.rb', line 11 def assoc(*kvs) associate(*kvs) end |
#associate(*kvs) ⇒ Object
7 8 9 |
# File 'lib/rupture/map.rb', line 7 def associate(*kvs) into(kvs.seq.partition(2)) end |
#destruct(*keys) ⇒ Object
37 38 39 40 |
# File 'lib/rupture/map.rb', line 37 def destruct(*keys) vals = keys.seq.map(self) block_given? ? yield(*vals) : vals end |
#into(other) ⇒ Object
15 16 17 18 19 |
# File 'lib/rupture/map.rb', line 15 def into(other) other.seq.reduce(as_map) do |map, (k,v)| map.put(k,v) end end |
#map? ⇒ Boolean
3 4 5 |
# File 'lib/rupture/map.rb', line 3 def map? true end |
#update(key, fn = nil, *args, &block) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rupture/map.rb', line 21 def update(key, fn = nil, *args, &block) if fn assoc(key, fn.call(self[key], *args, &block)) else assoc(key, yield(self[key])) end end |
#update_each(keys, *args, &block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rupture/map.rb', line 29 def update_each(keys, *args, &block) map = as_map keys.each do |key| update(key, *args, &block) end map end |