streamlet 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +15 -14
- data/lib/streamlet.rb +7 -9
- data/lib/streamlet/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b807a2584971430cec78a285428d5e3130e84c5
|
4
|
+
data.tar.gz: 017ff51d4646ef1bb90b09cfedd4bd9397241526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
and_then
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
and_then
|
39
|
-
and_then
|
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
|
|
data/lib/streamlet.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
class Streamlet
|
2
|
-
|
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(
|
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
|
|
data/lib/streamlet/version.rb
CHANGED
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.
|
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-
|
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.
|
96
|
+
rubygems_version: 2.6.10
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: A little stream of failible operations
|