funkr 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/funkr/extensions/enumerable.rb +6 -3
- data/lib/funkr/version.rb +1 -1
- data/test/tests.rb +2 -2
- metadata +3 -3
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
module Enumerable
|
2
3
|
|
3
4
|
# enumerable extensions
|
@@ -54,7 +55,9 @@ module Enumerable
|
|
54
55
|
self.sliding_groups_of(seq.size).index(seq)
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
+
# Prend un prédicat p(x,y), et construit un tableau dans lequel tous
|
59
|
+
# les couples (a,b), tels que 'a' précède 'b', vérifient p(a,b).
|
60
|
+
def make_uniq_by(&block)
|
58
61
|
result = []
|
59
62
|
self.each do |e|
|
60
63
|
unless result.any?{|x| yield(x,e)} then result.push(e) end
|
@@ -66,8 +69,8 @@ module Enumerable
|
|
66
69
|
# codé en impératif parce que inject est trop lent :(
|
67
70
|
def diff_with(other, &block)
|
68
71
|
m, i, a = [], [], []
|
69
|
-
u_s = self.
|
70
|
-
u_o = other.
|
72
|
+
u_s = self.make_uniq_by(&block)
|
73
|
+
u_o = other.make_uniq_by(&block)
|
71
74
|
u_s.each do |e|
|
72
75
|
if u_o.find{|x| yield(e,x)} then i.push(e) # intersection
|
73
76
|
else m.push(e) end # missing
|
data/lib/funkr/version.rb
CHANGED
data/test/tests.rb
CHANGED
@@ -94,6 +94,6 @@ a = [ {:v => 1}, {:v => 2}, {:v => 3}, {:v => 2}, {:v => 3} ]
|
|
94
94
|
b = [ {:v => 2}, {:v => 3}, {:v => 4}, {:v => 3}, {:v => 4} ]
|
95
95
|
puts(a.diff_with(b){|x,y| x[:v] == y[:v]}.inspect)
|
96
96
|
|
97
|
-
puts "\n>
|
97
|
+
puts "\n> make_uniq_by"
|
98
98
|
a = [ {:v => 1}, {:v => 2}, {:v => 3}, {:v => 2}, {:v => 3}, {:v => 1} ]
|
99
|
-
puts(a.
|
99
|
+
puts(a.make_uniq_by{|x,y| x[:v] == y[:v]}.inspect)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 12
|
9
|
+
version: 0.0.12
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Paul Rivier
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-06-07 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|