Sha256: 193c254a0539aad117959dd4791020c6f6022419d6a1cd8f3b377ee925a4b113
Contents?: true
Size: 1.13 KB
Versions: 2
Compression:
Stored size: 1.13 KB
Contents
module Pair def pair(first, second) Pair.new(first, second) end def from_map(a_map) Pair.from_map(a_map) end class Pair def initialize(first, second) @first = -> { first } @second = -> { second } end def first @first.call end alias key first def second @second.call end def first=(v) @first = -> { v } end alias key= first= def second=(v) @second = -> { v } end alias value= second= def each(&block) [first,second].each do |i| block.call(i) end end alias value second def to_map {first => second} end def self.from_map(a_map) from_single(a_map).map { |k, v| Pair.new(k, v) } end def to_s Type.responds_all(sequence(first, second), :to_s) {first.to_s => second.to_s} end def to_i Type.responds_all(sequence(first, second), :to_i) {first.to_i => second.to_i} end def to_f Type.responds_all(sequence(first, second), :to_f) {first.to_f => second.to_f} end def values sequence(first, second) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
totally_lazy-0.0.13 | lib/pair.rb |
totally_lazy-0.0.12 | lib/pair.rb |