piperator 0.2.0 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/lib/piperator.rb +9 -0
- data/lib/piperator/pipeline.rb +27 -5
- data/lib/piperator/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ce14dd4a45b8ce9bc5453cb30df67c1357c8903
|
4
|
+
data.tar.gz: b3df089403c086b52d8f0a48d2292d9f06495c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e93f487947ca4c0bacc904b3b04d1e90a245a3bc2efa68bb2b461f3df0427b6e34182cfc01c8cb50be9ae79906de91848ee70102687b55b31d769ed4938f40d9
|
7
|
+
data.tar.gz: 0a2e61d19a4533ac76bb302f6fbc505f7a8e4cf5e97f0652ab9bd6b8f34aff1e79e22d271c12656a7e7a0b0cb460be2f6f3e681bbdf6e31d4c55c06f2296499c
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -35,11 +35,11 @@ Piperator.
|
|
35
35
|
# => 18
|
36
36
|
```
|
37
37
|
|
38
|
-
If desired, the input enumerable can also be given as the first
|
38
|
+
If desired, the input enumerable can also be given as the first elmenent of the pipeline using `Piperator.wrap`.
|
39
39
|
|
40
40
|
```ruby
|
41
41
|
Piperator.
|
42
|
-
|
42
|
+
wrap([1, 2, 3]).
|
43
43
|
pipe(->(values) { values.lazy.map { |i| i * 3 } }).
|
44
44
|
pipe(->(values) { values.sum }).
|
45
45
|
call
|
data/lib/piperator.rb
CHANGED
@@ -12,4 +12,13 @@ module Piperator
|
|
12
12
|
def self.pipe(enumerable)
|
13
13
|
Pipeline.pipe(enumerable)
|
14
14
|
end
|
15
|
+
|
16
|
+
# Build a new pipeline from a from a non-callable, i.e. string, array, etc.
|
17
|
+
#
|
18
|
+
# @see Piperator::Pipeline.wrap
|
19
|
+
# @param value A raw value which will be passed through the pipeline
|
20
|
+
# @return [Pipeline] A pipeline containing only the callable
|
21
|
+
def self.wrap(value)
|
22
|
+
Pipeline.wrap(value)
|
23
|
+
end
|
15
24
|
end
|
data/lib/piperator/pipeline.rb
CHANGED
@@ -11,11 +11,23 @@ module Piperator
|
|
11
11
|
# @param callable An object responding to call(enumerable)
|
12
12
|
# @return [Pipeline] A pipeline containing only the callable
|
13
13
|
def self.pipe(callable)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
Pipeline.new([callable])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Build a new pipeline from a from a non-callable, i.e. string, array, etc.
|
18
|
+
# This method will wrap the value in a proc, thus making it callable.
|
19
|
+
#
|
20
|
+
# Piperator::Pipeline.wrap([1, 2, 3]).pipe(add_one)
|
21
|
+
# # => [2, 3, 4]
|
22
|
+
#
|
23
|
+
# # Wrap is syntactic sugar for wrapping a value in a proc
|
24
|
+
# Piperator::Pipeline.pipe(->(_) { [1, 2, 3] }).pipe(add_one)
|
25
|
+
# # => [2, 3, 4]
|
26
|
+
#
|
27
|
+
# @param value A raw value which will be passed through the pipeline
|
28
|
+
# @return [Pipeline] A pipeline containing only the callable
|
29
|
+
def self.wrap(value)
|
30
|
+
Pipeline.new([->(_) { value }])
|
19
31
|
end
|
20
32
|
|
21
33
|
# Returns enumerable given as an argument without modifications. Usable when
|
@@ -29,6 +41,7 @@ module Piperator
|
|
29
41
|
|
30
42
|
def initialize(pipes = [])
|
31
43
|
@pipes = pipes
|
44
|
+
freeze
|
32
45
|
end
|
33
46
|
|
34
47
|
# Compute the pipeline and return a lazy enumerable with all the pipes.
|
@@ -53,5 +66,14 @@ module Piperator
|
|
53
66
|
def pipe(other)
|
54
67
|
Pipeline.new(@pipes + [other])
|
55
68
|
end
|
69
|
+
|
70
|
+
# Add a new value to the pipeline
|
71
|
+
#
|
72
|
+
# @param other A value which is wrapped into a pipe, then appended to the
|
73
|
+
# pipeline.
|
74
|
+
# @return [Pipeline] A new pipeline instance
|
75
|
+
def wrap(other)
|
76
|
+
Pipeline.new(@pipes + [->(_) { other }])
|
77
|
+
end
|
56
78
|
end
|
57
79
|
end
|
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: 0.
|
4
|
+
version: 0.3.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: 2017-
|
11
|
+
date: 2017-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- ".rspec"
|
65
65
|
- ".travis.yml"
|
66
|
+
- CHANGELOG.md
|
66
67
|
- Gemfile
|
67
68
|
- LICENSE.txt
|
68
69
|
- README.md
|