mprelude 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mprelude.rb +8 -10
- data/mprelude.gemspec +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/mprelude/either_spec.rb +7 -7
- data/spec/unit/mprelude/maybe_spec.rb +5 -5
- 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: f41b72673c3d3d33030bf04fa7de7fd8ec875b79f5a408601d6c83d6b64cdf86
|
4
|
+
data.tar.gz: cb2b0c662dc4c00d8626245579750e1d472550ff9ce69b4dd4be047dc1dd4587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e013c91f2f15500728b3a57a592ad359b0d87d56b948bb1fec485196c288293cbc3b9cee3985c7f50d9d25d3442fb92881e25eefb93776cf2ffc6467443888f
|
7
|
+
data.tar.gz: dd114660d4dbfb284fe7c172f31541a7e89885b7eb5709f94ac7b239785a790ea5d8443d084a3ca4f006b139432de5abe3677eb9c58683016160d29a69c242ff
|
data/lib/mprelude.rb
CHANGED
@@ -5,11 +5,9 @@ require 'adamantium'
|
|
5
5
|
require 'concord'
|
6
6
|
|
7
7
|
module MPrelude
|
8
|
-
module
|
8
|
+
module RequireBlock
|
9
9
|
include AbstractType
|
10
10
|
|
11
|
-
abstract_method :fmap
|
12
|
-
|
13
11
|
private
|
14
12
|
|
15
13
|
# Raise error unless block is provided
|
@@ -22,13 +20,13 @@ module MPrelude
|
|
22
20
|
fail LocalJumpError unless block_given?
|
23
21
|
self
|
24
22
|
end
|
25
|
-
end #
|
23
|
+
end # RequireBLock
|
26
24
|
|
27
25
|
class Maybe
|
28
26
|
include(
|
29
27
|
AbstractType,
|
30
28
|
Adamantium::Flat,
|
31
|
-
|
29
|
+
RequireBlock
|
32
30
|
)
|
33
31
|
|
34
32
|
class Nothing < self
|
@@ -46,7 +44,7 @@ module MPrelude
|
|
46
44
|
# Evaluate applicative block
|
47
45
|
#
|
48
46
|
# @return [Maybe::Nothing]
|
49
|
-
def
|
47
|
+
def bind(&block)
|
50
48
|
require_block(&block)
|
51
49
|
end
|
52
50
|
end # Nothing
|
@@ -64,7 +62,7 @@ module MPrelude
|
|
64
62
|
# Evalute applicative block
|
65
63
|
#
|
66
64
|
# @return [Maybe]
|
67
|
-
def
|
65
|
+
def bind
|
68
66
|
yield(value)
|
69
67
|
end
|
70
68
|
end # Just
|
@@ -75,7 +73,7 @@ module MPrelude
|
|
75
73
|
AbstractType,
|
76
74
|
Adamantium::Flat,
|
77
75
|
Concord.new(:value),
|
78
|
-
|
76
|
+
RequireBlock
|
79
77
|
)
|
80
78
|
|
81
79
|
# Execute block and wrap error in left
|
@@ -114,7 +112,7 @@ module MPrelude
|
|
114
112
|
# Evaluate applicative block
|
115
113
|
#
|
116
114
|
# @return [Either::Left<Object>]
|
117
|
-
def
|
115
|
+
def bind(&block)
|
118
116
|
require_block(&block)
|
119
117
|
end
|
120
118
|
|
@@ -166,7 +164,7 @@ module MPrelude
|
|
166
164
|
# Evaluate applicative block
|
167
165
|
#
|
168
166
|
# @return [Either<Object>]
|
169
|
-
def
|
167
|
+
def bind
|
170
168
|
yield(value)
|
171
169
|
end
|
172
170
|
|
data/mprelude.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -28,7 +28,7 @@ RSpec.shared_examples 'returns self' do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
RSpec.shared_examples '#
|
31
|
+
RSpec.shared_examples '#bind block evaluation' do
|
32
32
|
it 'evaluates block and returns its wrapped result' do
|
33
33
|
expect { expect(apply).to eql(block_result) }
|
34
34
|
.to change(yields, :to_a)
|
@@ -113,9 +113,9 @@ RSpec.describe MPrelude::Either::Left do
|
|
113
113
|
include_examples 'returns self'
|
114
114
|
end
|
115
115
|
|
116
|
-
describe '#
|
116
|
+
describe '#bind' do
|
117
117
|
def apply
|
118
|
-
subject.
|
118
|
+
subject.bind(&block)
|
119
119
|
end
|
120
120
|
|
121
121
|
include_examples 'no block evaluation'
|
@@ -186,7 +186,7 @@ RSpec.describe MPrelude::Either::Left do
|
|
186
186
|
subject.either(block, -> { fail })
|
187
187
|
end
|
188
188
|
|
189
|
-
include_examples '#
|
189
|
+
include_examples '#bind block evaluation'
|
190
190
|
end
|
191
191
|
|
192
192
|
describe '#left?' do
|
@@ -233,13 +233,13 @@ RSpec.describe MPrelude::Either::Right do
|
|
233
233
|
include_examples 'Functor#fmap block evaluation'
|
234
234
|
end
|
235
235
|
|
236
|
-
describe '#
|
236
|
+
describe '#bind' do
|
237
237
|
def apply
|
238
|
-
subject.
|
238
|
+
subject.bind(&block)
|
239
239
|
end
|
240
240
|
|
241
241
|
include_examples 'requires block'
|
242
|
-
include_examples '#
|
242
|
+
include_examples '#bind block evaluation'
|
243
243
|
end
|
244
244
|
|
245
245
|
describe '#from_left' do
|
@@ -309,7 +309,7 @@ RSpec.describe MPrelude::Either::Right do
|
|
309
309
|
subject.either(-> { fail }, block)
|
310
310
|
end
|
311
311
|
|
312
|
-
include_examples '#
|
312
|
+
include_examples '#bind block evaluation'
|
313
313
|
end
|
314
314
|
|
315
315
|
describe '#left?' do
|
@@ -15,9 +15,9 @@ RSpec.describe MPrelude::Maybe::Nothing do
|
|
15
15
|
include_examples 'returns self'
|
16
16
|
end
|
17
17
|
|
18
|
-
describe '#
|
18
|
+
describe '#bind' do
|
19
19
|
def apply
|
20
|
-
subject.
|
20
|
+
subject.bind(&block)
|
21
21
|
end
|
22
22
|
|
23
23
|
include_examples 'no block evaluation'
|
@@ -49,12 +49,12 @@ RSpec.describe MPrelude::Maybe::Just do
|
|
49
49
|
include_examples 'Functor#fmap block evaluation'
|
50
50
|
end
|
51
51
|
|
52
|
-
describe '#
|
52
|
+
describe '#bind' do
|
53
53
|
def apply
|
54
|
-
subject.
|
54
|
+
subject.bind(&block)
|
55
55
|
end
|
56
56
|
|
57
57
|
include_examples 'requires block'
|
58
|
-
include_examples '#
|
58
|
+
include_examples '#bind block evaluation'
|
59
59
|
end
|
60
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mprelude
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_type
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
|
-
rubygems_version: 3.0.
|
134
|
+
rubygems_version: 3.0.3
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Mostly an either type
|