funtools 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/funtools/cons.rb +13 -14
  3. data/lib/funtools.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0faa0f3d082df30457dbd13eae82d9d78b582cda
4
- data.tar.gz: ea596071898a6e7eca90869cc3b31fba9165c8b6
3
+ metadata.gz: 760735a64660eda23cf109045b3696041da6e8a4
4
+ data.tar.gz: 610702e131264a06618c6e4a31b7742ca5e7e623
5
5
  SHA512:
6
- metadata.gz: 5397fff059b62f1b280866424d72fcb28724ca691246cd7f350a0c0439b889dc0bcc57e31a4131b0b775400da0a348c00fad2028409e491fa44dc777cf6b1875
7
- data.tar.gz: 510345cfabb0889d1debd002ac34624309358e040d02132824e97ebba5f59bd77347baa78550a9edd79664ecfb8b993e92a09b213850993e9efcda21fa6821ca
6
+ metadata.gz: 225ca09218729ba85fab9a6fa331b1d8f3d3fd7a6a857ae28f06cb945e7c26daaf5da98f7797a6a054477a294f73463d78cd239d175a6ed919bf2a14e9af1f39
7
+ data.tar.gz: d340f6d4c99996b7202f4a7ce1273d8850f68e6c842800646186a838781af57aa7b1a0240c0428df924e080841b523f1fe2a1fba121c43d2327cd195e60dedcd
data/lib/funtools/cons.rb CHANGED
@@ -46,20 +46,20 @@ class Cons
46
46
  # Yields each element.
47
47
  def each(&block)
48
48
  block.(car)
49
- right = cdr
49
+ left, right = car, cdr
50
50
 
51
51
  while right
52
52
  if right.is_a?(Cons)
53
- if [right.car, right.cdr].grep(Cons).any? || right.cdr.nil?
54
- block.(right.car)
55
- right = right.cdr
56
- else
53
+ if left.is_a?(Cons)
57
54
  block.(right)
58
55
  right = nil
56
+ else
57
+ block.(right.car)
58
+ left, right = right.car, right.cdr
59
59
  end
60
60
  else
61
- block.(right) unless right.nil?
62
- right = nil
61
+ block.(right) unless right.nil?
62
+ right = nil
63
63
  end
64
64
  end
65
65
  end
@@ -78,15 +78,14 @@ class Cons
78
78
  #
79
79
  # Returns a String.
80
80
  def inspect
81
- last = nil
82
- r = [1].cycle.reduce([self]) do |c,_|
83
- break c if c == last
84
- last = c
85
- c.flatten.map do |e|
81
+ result = [self]
82
+ while result.grep(Cons).any?
83
+ result = result.map do |e|
86
84
  e.is_a?(Cons) ? ['(', e.to_a.zip([' '].cycle).flatten[0..-2], ')'] :
87
85
  e.nil? ? 'nil' : e
88
- end
89
- end.map(&:to_s).join
86
+ end.flatten
87
+ end
88
+ result.map(&:to_s).join
90
89
  end
91
90
  alias :to_s :inspect
92
91
  end
data/lib/funtools.rb CHANGED
@@ -4,5 +4,5 @@ require 'funtools/composition'
4
4
  require 'funtools/pattern-matching'
5
5
 
6
6
  module Funtools
7
- VERSION = '0.5.0'
7
+ VERSION = '0.5.1'
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina Wuest