streamlet 0.0.1 → 0.0.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
- SHA256:
3
- metadata.gz: 5e975e3ace595a7d7947f2550243f30d97a1eba8dafc93b046831655918bfb39
4
- data.tar.gz: 64e4eaf84d118bfb3c9013d1c1038e4c8295d82ff46fbc01698057f048d04971
2
+ SHA1:
3
+ metadata.gz: 2b807a2584971430cec78a285428d5e3130e84c5
4
+ data.tar.gz: 017ff51d4646ef1bb90b09cfedd4bd9397241526
5
5
  SHA512:
6
- metadata.gz: 5f65ffde065332acfcd733fb1a1a4b3498730ac9ede10ef437aced824ccf20fcae592ab041582dc2125a943f7c828b359550941862cc760982799abed90a9390
7
- data.tar.gz: 97ed0c7991814d724bd05525f60e0d36eb4e50c6be77affdadd7bd87d08d1a3f9be0ffbf0931bca6a732e1127c4205bd24ef8d561e1d2d094dcd2ac94e0aa899
6
+ metadata.gz: fa5b3af51c57e819cb568f5567a49bceb6bbeb600867b8cde16548ab4353cb700ddc2e042f3ae03cbc55a977fc63d95459d617b384c00b45d1cf783c3e99fe3b
7
+ data.tar.gz: 2a56da418548eb3217bcfc958e21e6c26b8f4a2bb0961e9d5016dbd9e6a23f33649107e96481ea6b23f251f89592fec4b140d410f6a5d8fa7d08e0d9bfec2cb1
data/README.md CHANGED
@@ -23,20 +23,21 @@ Or install it yourself as:
23
23
  ## Usage
24
24
 
25
25
  ```ruby
26
- success = 1
27
- failure = nil
28
-
29
- Streamlet.new(proc { success }).
30
- and_then(proc { |val| increment(val) }).
31
- and_then(proc { |val| increment(val) }).
32
- and_then(proc { |val| increment(val) }).
33
- result # => 4
34
-
35
- Streamlet.new(proc { success }).
36
- and_then(proc { |val| increment(val) }).
37
- and_then(proc { failure }).
38
- and_then(proc { |val| increment(val) }).
39
- and_then(proc { |val| increment(val) }).
26
+ def half_to_whole_number(number)
27
+ halved = number.to_f / 2
28
+ halved % 1 == 0 ? halved.to_i : nil
29
+ end
30
+
31
+ Streamlet.new { half_to_whole_number(16) }. # => 8
32
+ and_then { |val| half_to_whole_number(val) }. # => 4
33
+ and_then { |val| half_to_whole_number(val) }. # => 2
34
+ and_then { |val| half_to_whole_number(val) }. # => 1
35
+ result # => 1
36
+
37
+ Streamlet.new { half_to_whole_number(12) }. # => 6
38
+ and_then { |val| half_to_whole_number(val) }. # => 3
39
+ and_then { |val| half_to_whole_number(val) }. # => nil
40
+ and_then { |val| half_to_whole_number(val) }. # no-op
40
41
  result # => nil
41
42
  ```
42
43
 
@@ -1,21 +1,19 @@
1
1
  class Streamlet
2
- VERSION = "0.1.0"
3
-
4
- def initialize(operation, *args)
5
- @operation = operation
2
+ def initialize(*args, &operation)
6
3
  @args = args
4
+ @operation = operation
7
5
  @success_test = proc { |resp| !!resp }
8
6
  end
9
7
 
10
- def set_success_test(success_test)
8
+ def set_success_test(&success_test)
11
9
  @success_test = success_test
12
10
  self
13
11
  end
14
12
 
15
- def and_then(next_operation)
13
+ def and_then(&next_operation)
16
14
  if success_test.call(result)
17
- Streamlet.new(next_operation, result).
18
- set_success_test(success_test)
15
+ Streamlet.new(result, &next_operation).
16
+ set_success_test(&success_test)
19
17
  else
20
18
  Failure.new(result)
21
19
  end
@@ -34,7 +32,7 @@ class Streamlet
34
32
  @result = result
35
33
  end
36
34
 
37
- def and_then(_)
35
+ def and_then(&_)
38
36
  self
39
37
  end
40
38
 
@@ -1,3 +1,3 @@
1
1
  class Streamlet
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streamlet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Wey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-02 00:00:00.000000000 Z
11
+ date: 2018-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.7.3
96
+ rubygems_version: 2.6.10
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: A little stream of failible operations