funkr 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,9 +17,10 @@ class Array
17
17
 
18
18
 
19
19
  # Array can be made an applicative functor, for example :
20
- # f = Array.curry_lift_proc{|x,y| x + y}
21
- # f.apply([0,4]).apply([5,7]) => [5, 7, 9, 11]
22
- # f.apply([0,4]).apply([]) => []
20
+ #
21
+ # f = Array.curry_lift_proc{|x,y| x + y}
22
+ # f.apply([0,4]).apply([5,7]) => [5, 7, 9, 11]
23
+ # f.apply([0,4]).apply([]) => []
23
24
  include Applicative
24
25
  extend Applicative::ClassMethods
25
26
 
@@ -49,10 +50,12 @@ class Array
49
50
  end
50
51
 
51
52
 
52
- # Array is also a monad
53
53
  include Monad
54
54
  extend Monad::ClassMethods
55
55
 
56
+ # Array is also a monad
57
+ #
58
+ # [1,2].bind{|x| [3,4].bind{|y| x + y}} # => [4,5,5,6]
56
59
  def bind(&block)
57
60
  self.map(&block).flatten(1)
58
61
  end
@@ -40,26 +40,27 @@ module Enumerable
40
40
  return [ inc, [] ]
41
41
  end
42
42
 
43
- # Constitue des groupes disjoints de n éléments au plus
43
+ # builds up disjoint groups of n elements or less
44
44
  def groups_of(n)
45
45
  g = self.take(n)
46
46
  return [] if g.empty?
47
47
  [g] + self.drop(n).groups_of(n)
48
48
  end
49
49
 
50
- # constitue des groupes de n éléments exactement, décalés de 1
50
+ # builds up sliding groups of exactly n elements
51
51
  def sliding_groups_of(n)
52
52
  return [] if self.size < n
53
53
  [ self.take(n) ] + self.drop(1).sliding_groups_of(n)
54
54
  end
55
55
 
56
- # trouve l'index d'une séquence
56
+ # find the position of a sequence
57
+ # [1,2,3,4,5,4,3,2,1].seq_index([4,3]) # => 5
57
58
  def seq_index(seq)
58
59
  self.sliding_groups_of(seq.size).index(seq)
59
60
  end
60
61
 
61
- # Prend un prédicat p(x,y), et construit un tableau dans lequel tous
62
- # les couples (a,b), tels que 'a' précède 'b', vérifient p(a,b).
62
+ # Takes a block predicate p(x,y) and builds an array of elements so
63
+ # that for any (a,b), a being before b in the list, p(a,b) holds.
63
64
  def make_uniq_by(&block)
64
65
  result = []
65
66
  self.each do |e|
@@ -68,8 +69,7 @@ module Enumerable
68
69
  return result
69
70
  end
70
71
 
71
- # difference entre 2 tableaux, retourne le triplet [ [missing] , [intersection], [added] ]
72
- # codé en impératif parce que inject est trop lent :(
72
+ # compare 2 enumerables, and returns [ [missing] , [intersection], [added] ]
73
73
  def diff_with(other, &block)
74
74
  m, i, a = [], [], []
75
75
  u_s = self.make_uniq_by(&block)
@@ -1,3 +1,3 @@
1
1
  module Funkr
2
- VERSION = "0.0.25"
2
+ VERSION = "0.0.26"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 25
9
- version: 0.0.25
8
+ - 26
9
+ version: 0.0.26
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul Rivier