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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +12 -0
- data/lib/piperator/builder.rb +3 -2
- data/lib/piperator/pipeline.rb +27 -0
- data/lib/piperator/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1475b2b74289ce3c32f638a67156b943101bff0b548283e2e1ea635d5048a6e5
|
4
|
+
data.tar.gz: 3d06228a633975fde9409387471bb505eb192971c8e50e7ce0df34bbc74e2ae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a11be79d16a0a54c21cb62518ce6426a184c9c9d6609dc6424533413d6cee875f57d74411d92b39dc57fbf9d25d5e712b112149d7bc16d3f42a6f972e52284a
|
7
|
+
data.tar.gz: e2cec664b6832086b53cdaa200b03852f6dcd62cb4f3c5b18532ea636054b0c599471d84a181857e36919cea400a68f1e6fdd93bdeb03e9f612107acdcd4768f
|
data/.travis.yml
CHANGED
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
|
data/lib/piperator/builder.rb
CHANGED
@@ -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
|
|
data/lib/piperator/pipeline.rb
CHANGED
@@ -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.
|
data/lib/piperator/version.rb
CHANGED
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.
|
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:
|
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.
|
98
|
+
rubygems_version: 3.1.2
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Composable pipelines for streaming large collections
|