Class: Hash
- Extended by:
- Monoid::ClassMethods
- Includes:
- Funkr::Categories, Monoid
- Defined in:
- lib/funkr/extensions/hash.rb
Overview
Extends Hash capabilities
Class Method Summary collapse
Instance Method Summary collapse
-
#map_k ⇒ Object
maps function over hash keys.
-
#map_kv ⇒ Object
maps function over hash keys and values.
-
#map_v ⇒ Object
maps function over hash values.
- #mplus(m_y) ⇒ Object
Class Method Details
.mzero ⇒ Object
35 |
# File 'lib/funkr/extensions/hash.rb', line 35 def mzero; self.new(); end |
Instance Method Details
#map_k ⇒ Object
maps function over hash keys
15 16 17 18 19 |
# File 'lib/funkr/extensions/hash.rb', line 15 def map_k # &block h = Hash.new(self.default) self.each{|k,v| h[yield(k)] = v} return h end |
#map_kv ⇒ Object
maps function over hash keys and values. Block should take 2 parameters, and should return a 2 elements array.
23 24 25 26 27 28 29 30 |
# File 'lib/funkr/extensions/hash.rb', line 23 def map_kv # &block h = Hash.new(self.default) self.each do |k,v| nk, nv = yield(k,v) h[nk] = nv end return h end |
#map_v ⇒ Object
maps function over hash values
8 9 10 11 12 |
# File 'lib/funkr/extensions/hash.rb', line 8 def map_v # &block h = Hash.new(self.default) self.each{|k,v| h[k] = yield(v)} return h end |
#mplus(m_y) ⇒ Object
49 50 51 |
# File 'lib/funkr/extensions/hash.rb', line 49 def mplus(m_y) self.merge(m_y){|k, v1, v2| v1.mplus(v2)} end |