piperator 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13c2413016f50d1f376666a3997bb0419fd3bbe0311913c9b2d694ab80b47083
4
- data.tar.gz: 5b452fb6d8bc029accb4c32cd5b692d377ead539cc164dd65f6aba4715d51c75
3
+ metadata.gz: 1475b2b74289ce3c32f638a67156b943101bff0b548283e2e1ea635d5048a6e5
4
+ data.tar.gz: 3d06228a633975fde9409387471bb505eb192971c8e50e7ce0df34bbc74e2ae1
5
5
  SHA512:
6
- metadata.gz: '07794c6e1760367b51fab0667afac9275fa61c81d34e1de3b1d68be245246a04d0040869e6e27f49e7d2de90057e0edddd3ab9bcba0cb0620fd4d61ac3112d7e'
7
- data.tar.gz: 372fc0fb1fc79832d312bf661019ff6f4203c702a139a3c3fe03ab8f8b2636826ade5a20fa60e288580177ae58f812320e6419ab341d9ac2bb80c51e9fa599d9
6
+ metadata.gz: 9a11be79d16a0a54c21cb62518ce6426a184c9c9d6609dc6424533413d6cee875f57d74411d92b39dc57fbf9d25d5e712b112149d7bc16d3f42a6f972e52284a
7
+ data.tar.gz: e2cec664b6832086b53cdaa200b03852f6dcd62cb4f3c5b18532ea636054b0c599471d84a181857e36919cea400a68f1e6fdd93bdeb03e9f612107acdcd4768f
@@ -6,5 +6,6 @@ rvm:
6
6
  - 2.4
7
7
  - 2.5
8
8
  - 2.6
9
+ - 2.7
9
10
  - jruby
10
11
  - truffleruby
data/README.md CHANGED
@@ -69,6 +69,18 @@ Piperator.
69
69
  # => 18
70
70
  ```
71
71
 
72
+ Have reasons to defer constructing a pipe? Evaluate it lazily:
73
+
74
+ ```ruby
75
+ summing = ->(values) { values.sum }
76
+ Piperator.build
77
+ pipe(->(values) { values.lazy.map { |i| i * 3 } })
78
+ lazy do
79
+ summing
80
+ end
81
+ end.call([1, 2, 3])
82
+ ```
83
+
72
84
  There is, of course, a much more idiomatic alternative in Ruby:
73
85
 
74
86
  ```ruby
@@ -16,11 +16,12 @@ module Piperator
16
16
  #
17
17
  # @see Pipeline.$1
18
18
  def self.dsl_method(method_name)
19
- define_method(method_name) do |*arguments|
20
- @pipeline = @pipeline.send(method_name, *arguments)
19
+ define_method(method_name) do |*arguments, &block|
20
+ @pipeline = @pipeline.send(method_name, *arguments, &block)
21
21
  end
22
22
  end
23
23
 
24
+ dsl_method :lazy
24
25
  dsl_method :pipe
25
26
  dsl_method :wrap
26
27
 
@@ -6,6 +6,20 @@ module Piperator
6
6
  # For streaming purposes, it usually is desirable to have pipes that takes
7
7
  # a lazy Enumerator as an argument a return a (modified) lazy Enumerator.
8
8
  class Pipeline
9
+ # Build a new pipeline from a lazily evaluated callable or an enumerable
10
+ # object.
11
+ #
12
+ # @param block A block returning a callable(enumerable)
13
+ # @return [Pipeline] A pipeline containing only the lazily evaluated
14
+ # callable.
15
+ def self.lazy(&block)
16
+ callable = nil
17
+ Pipeline.new([lambda do |e|
18
+ callable ||= block.call
19
+ callable.call(e)
20
+ end])
21
+ end
22
+
9
23
  # Build a new pipeline from a callable or an enumerable object
10
24
  #
11
25
  # @param callable An object responding to call(enumerable)
@@ -59,6 +73,19 @@ module Piperator
59
73
  call(enumerable).to_a
60
74
  end
61
75
 
76
+ # Add a new lazily evaluated part to the pipeline.
77
+ #
78
+ # @param block A block returning a callable(enumerable) to append in
79
+ # pipeline.
80
+ # @return [Pipeline] A new pipeline instance
81
+ def lazy(&block)
82
+ callable = nil
83
+ Pipeline.new(@pipes + [lambda do |e|
84
+ callable ||= block.call
85
+ callable.call(e)
86
+ end])
87
+ end
88
+
62
89
  # Add a new part to the pipeline
63
90
  #
64
91
  # @param other A pipe to append in pipeline. Responds to #call.
@@ -1,4 +1,4 @@
1
1
  module Piperator
2
2
  # Piperator version
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piperator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ville Lautanala
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-06 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.0.3
98
+ rubygems_version: 3.1.2
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Composable pipelines for streaming large collections