double_linked_list 0.3.1 → 0.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fc4807723f5a75b6867aa8962b01d1123cf0cc4
4
- data.tar.gz: c261b1e957e7ad46c4b6d2f332410f581e901532
3
+ metadata.gz: feab77ef8adb57a32be8e66ea3ceb36d27b7c48f
4
+ data.tar.gz: af9e03f9681a2ef41d6465a06e8cca63e9c6f94f
5
5
  SHA512:
6
- metadata.gz: 9430a741a460c9b15d96fc8a64a48210b2895c82c80c64bbac87c1a5986989f7c08de2485e47423ec90b99c35aae355b39c7b9ce57af2021b165bf1d75241e3a
7
- data.tar.gz: 9ee6ecbc06eb14f4511cf2cece5c6e5d5601a82088fd75d91e6ae843592d4b070bc3c60abb43a03f895d21f41a66412b729b0903365bba896f76c87f0b5d1e21
6
+ metadata.gz: 5a5a1be7aa0965dda4560b0d98b72e690162bce07cad1fbfebb4cd46f15a097504bd41fb754339639e36128bf98ecdeea24b3b855115443c92a186a9844824ba
7
+ data.tar.gz: 4bbf0deae7c97ad7c8b0e33118159bd0c69222a589de14885d270c54086a13b5436c56757479842e538036a01009ba7a2c0561801351edaab3d1842ab9bd0357
data/README.md CHANGED
@@ -123,6 +123,18 @@ chunked.first.last.datum #=> 2
123
123
  chunked.map{|ll| ll.to_a } #=> [[1, 2], [3, 4]]
124
124
  ```
125
125
 
126
+ A custom dll can be provided to enhance dll outputs
127
+
128
+ ```ruby
129
+ class CustomDLL < DoubleLinkedList; end
130
+
131
+ llist = DoubleLinkedList.from_a(1, 2, 3, 4)
132
+ chunked = llist.chunk_by do |e, current_llist|
133
+ e.datum == 3 && current_llist.head.datum == 1
134
+ end
135
+ chunked.first.is_a? CustomDLL #=> true
136
+ ```
137
+
126
138
  __select_by:__
127
139
 
128
140
  For selecting fractions of the linked list avoiding the elements not returned in between the selected head and last sequences.
@@ -1,7 +1,16 @@
1
1
  class DoubleLinkedList
2
- class Element < Struct.new(:datum, :previous, :_next)
2
+ class Element
3
3
  include Enumerable
4
4
 
5
+ attr_reader :datum
6
+ attr_accessor :previous, :_next
7
+
8
+ def initialize(datum, previous = nil, _next = nil)
9
+ @datum = datum
10
+ @previous = previous
11
+ @_next = _next
12
+ end
13
+
5
14
  alias_method :next, :_next
6
15
  alias_method :prev, :previous
7
16
 
@@ -16,19 +25,19 @@ class DoubleLinkedList
16
25
  end
17
26
 
18
27
  def count
19
- reduce(0) { |p, n| p + 1 }
28
+ reduce(0) { |p| p + 1 }
20
29
  end
21
30
  alias_method :included_next_count, :count
22
31
 
23
32
  def next_count
24
33
  c = 0
25
- _each { |n| c += 1 }
34
+ _each { c += 1 }
26
35
  c
27
36
  end
28
37
 
29
38
  def prev_count
30
39
  c = 0
31
- _reverse_each { |n| c += 1 }
40
+ _reverse_each { c += 1 }
32
41
  c
33
42
  end
34
43
 
@@ -69,12 +78,12 @@ class DoubleLinkedList
69
78
  new_last
70
79
  end
71
80
 
72
- def chunk_by(acc, &block)
81
+ def chunk_by(acc, custom_dll = DoubleLinkedList, &block)
73
82
  if acc.empty?
74
- acc << DoubleLinkedList.from_a(self.datum)
83
+ acc << custom_dll.from_a(self.datum)
75
84
  else
76
85
  if block.call(self, acc.last, acc)
77
- acc << DoubleLinkedList.from_a(self.datum)
86
+ acc << custom_dll.from_a(self.datum)
78
87
  else
79
88
  acc.last << self.datum
80
89
  end
@@ -1,3 +1,3 @@
1
1
  class DoubleLinkedList
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -58,8 +58,8 @@ class DoubleLinkedList
58
58
  last.find_previous_by(false, &block)
59
59
  end
60
60
 
61
- def chunk_by(&block)
62
- head.chunk_by([], &block)
61
+ def chunk_by(custom_dll = DoubleLinkedList, &block)
62
+ head.chunk_by([], custom_dll, &block)
63
63
  end
64
64
 
65
65
  def select_by(&block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: double_linked_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Pañach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler