rstructural 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -0
- data/lib/rstructural/struct.rb +5 -0
- data/rstructural.gemspec +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68d3611d22597d67e3a4d481d07cce3e029544f1852d05c32dd84c7fea4f2426
|
4
|
+
data.tar.gz: '06693abe983552f132d9874780e8d1c1be0a33d4e41b3a1078a214f888796034'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d8ed0bf31f77f652bc6392e161560e4fd410fa148d84acd39b3ae558347d9d0c43e98555534815121ef2c9d641a6f49373199a0aafefd11b8ebd97ddeeabe37
|
7
|
+
data.tar.gz: 36a15de7dad8594103c8e2e0dd9ed0e3b7b9dbea72aa227e13c3824caf2340bff534d40c8ab55abf0d357f69a3c8a6fc51f3c20099e6426bb292aedb21f53e6a
|
data/README.md
CHANGED
@@ -11,6 +11,13 @@
|
|
11
11
|
- A set of objects
|
12
12
|
- A object is a constant or a set of objects
|
13
13
|
|
14
|
+
### Applied Types
|
15
|
+
|
16
|
+
- Option
|
17
|
+
- Some or None
|
18
|
+
- Either
|
19
|
+
- Left or Right
|
20
|
+
|
14
21
|
## Installation
|
15
22
|
|
16
23
|
Add this line to your application's Gemfile:
|
@@ -157,6 +164,41 @@ module AdtSample
|
|
157
164
|
end
|
158
165
|
```
|
159
166
|
|
167
|
+
### Rstructural::Option
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
puts Option.of(100).map { |v| v * 2 } #=> Option::Some(value: 200)
|
171
|
+
puts Option.of(nil).map { |v| v * 2 } #=> Option::None
|
172
|
+
puts Option.of(100).flat_map { |v| Option.of(v * 2) } #=> Option::Some(value: 200)
|
173
|
+
puts Option.of(100).flat_map { |v| v * 2 } #=> 200
|
174
|
+
puts Option.of(nil).flat_map { |v| Option.of(v * 2) } #=> Option::None
|
175
|
+
puts Option.of(100).get_or_else { 0 } #=> 100
|
176
|
+
puts Option.of(nil).get_or_else(0) #=> 0
|
177
|
+
puts Option.of(nil).get_or_else { 0 } #=> 0
|
178
|
+
puts Option.of(nil).is_a?(Option) #=> true
|
179
|
+
```
|
180
|
+
|
181
|
+
### Rstructural::Either
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
puts Either.try { 100 } #=> Either::Right(value: 100)
|
185
|
+
puts Either.try { raise "this is error" } #=> Either::Left(value: this is error)
|
186
|
+
puts Either.try { raise "this is error" }.value.inspect #=> #<RuntimeError: this is error>
|
187
|
+
puts Either.right(100).map { |v| v * 2 } #=> Either::Right(value: 200)
|
188
|
+
puts Either.left(100).map { |v| v * 2 } #=> Either::Left(value: 100)
|
189
|
+
puts Either.left(100).map_left { |v| v * 2 } #=> Either::Left(value: 200)
|
190
|
+
puts Either.right(100).flat_map { |v| Either.right(v * 2) } #=> Either::Right(value: 200)
|
191
|
+
puts Either.right(100).flat_map { |v| Either.left(v * 2) } #=> Either::Left(value: 200)
|
192
|
+
puts Either.left(100).flat_map { |v| Either.right(v * 2) } #=> Either::Left(value: 100)
|
193
|
+
puts Either.left(100).flat_map_left { |v| Either.right(v * 2) } #=> Either::Right(value: 200)
|
194
|
+
puts Either.right(100).right_or_else { 0 } #=> 100
|
195
|
+
puts Either.left(100).right_or_else { 0 } #=> 0
|
196
|
+
puts Either.right(100).left_or_else { 0 } #=> 0
|
197
|
+
puts Either.left(100).left_or_else { 0 } #=> 100
|
198
|
+
puts Either.right(100).right? #=> true
|
199
|
+
puts Either.right(100).left? #=> false
|
200
|
+
```
|
201
|
+
|
160
202
|
## Development
|
161
203
|
|
162
204
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/rstructural/struct.rb
CHANGED
@@ -30,6 +30,11 @@ module Rstructural
|
|
30
30
|
"#{class_name}"
|
31
31
|
end
|
32
32
|
|
33
|
+
def [](key)
|
34
|
+
_key = ("@" + key.to_s).to_sym
|
35
|
+
self.instance_variable_get(_key)
|
36
|
+
end
|
37
|
+
|
33
38
|
def ==(other)
|
34
39
|
return false if other.class != self.class
|
35
40
|
#{attributes.empty? ? true : attributes.map { |attr| "other.#{attr} == self.#{attr}" }.join(" && ")}
|
data/rstructural.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rstructural
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- petitviolet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- ".travis.yml"
|
36
36
|
- CODE_OF_CONDUCT.md
|
37
37
|
- Gemfile
|
38
|
-
- Gemfile.lock
|
39
38
|
- LICENSE.txt
|
40
39
|
- README.md
|
41
40
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rstructural (0.2.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
byebug (11.0.1)
|
10
|
-
minitest (5.13.0)
|
11
|
-
rake (12.3.3)
|
12
|
-
|
13
|
-
PLATFORMS
|
14
|
-
ruby
|
15
|
-
|
16
|
-
DEPENDENCIES
|
17
|
-
byebug
|
18
|
-
minitest (~> 5.0)
|
19
|
-
rake (~> 12.0)
|
20
|
-
rstructural!
|
21
|
-
|
22
|
-
BUNDLED WITH
|
23
|
-
2.1.2
|