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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eec6368ee594785c21b367e0575ff8e56b1333c9
4
- data.tar.gz: 7f4dc49b0dbab3b79bbd171b0099b7c0d623c157
3
+ metadata.gz: 5ce14dd4a45b8ce9bc5453cb30df67c1357c8903
4
+ data.tar.gz: b3df089403c086b52d8f0a48d2292d9f06495c51
5
5
  SHA512:
6
- metadata.gz: a784c23791a28b994d4db90626589478b58dfff806a35f3fc812792ed8c247fef556d5e72b1a2aa7195b97fbc0f73e0deab4d80cf9a03e91e393e1af809bc7e6
7
- data.tar.gz: f0e310f29dc9965e0f8a94826e0a66830761d4333aae8884cfb05e64cba35ea359657aa25e8046d37e98e30a1c18029dc670303765cd2f139a75ce9f87faf1fc
6
+ metadata.gz: e93f487947ca4c0bacc904b3b04d1e90a245a3bc2efa68bb2b461f3df0427b6e34182cfc01c8cb50be9ae79906de91848ee70102687b55b31d769ed4938f40d9
7
+ data.tar.gz: 0a2e61d19a4533ac76bb302f6fbc505f7a8e4cf5e97f0652ab9bd6b8f34aff1e79e22d271c12656a7e7a0b0cb460be2f6f3e681bbdf6e31d4c55c06f2296499c
@@ -0,0 +1,4 @@
1
+ ## 0.3.0 (13 July 2017)
2
+
3
+ - remove implicit wrapping to callable from `Pipeline.pipe`
4
+ - add `Pipeline.wrap` to wrap a value as callable
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 pipe.
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
- pipe([1, 2, 3]).
42
+ wrap([1, 2, 3]).
43
43
  pipe(->(values) { values.lazy.map { |i| i * 3 } }).
44
44
  pipe(->(values) { values.sum }).
45
45
  call
@@ -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
@@ -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
- if callable.respond_to?(:call)
15
- Pipeline.new([callable])
16
- else
17
- Pipeline.new([->(_) { callable }])
18
- end
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
@@ -1,3 +1,3 @@
1
1
  module Piperator
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  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: 0.2.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-06-06 00:00:00.000000000 Z
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