trither 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/trither.rb +3 -0
- data/lib/trither/either.rb +35 -0
- data/lib/trither/try.rb +57 -0
- data/lib/trither/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5c648f1df2c2c5670107f15157ff51b6a8486db
|
4
|
+
data.tar.gz: 0fc967a6005772f9bec03b23475aeb219dba0e5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a4b460e8c0cef866591621608dab9fd414ad1022d692308b60fffb93034b95fe0919c87fa6329c48f56cdf2687ad6e72c6b4b5b7ae375db6f7141eb6f70acf2
|
7
|
+
data.tar.gz: dc55a57e8fe119e85ba8c89356e78f0af410ccb088488bdcb95350929cf345a51b80ba089598a87e5f7890f0001904a486e0f487eda181b087b201e8d2240618
|
data/lib/trither.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Either
|
2
|
+
class Base
|
3
|
+
def initialize(value)
|
4
|
+
@value = value
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Left < Base
|
9
|
+
def left?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def right?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
def left
|
18
|
+
@value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Right < Base
|
23
|
+
def left?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def right?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def right
|
32
|
+
@value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/trither/try.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Try
|
2
|
+
class Base
|
3
|
+
def initialize(value)
|
4
|
+
@value = value
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Failure < Base
|
9
|
+
def failure?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def then
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_success
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def fail_map
|
22
|
+
Failure.new(yield @value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def on_failure
|
26
|
+
Result.new(yield @value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Success < Base
|
31
|
+
def failure?
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def then
|
36
|
+
yield @value
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_success
|
40
|
+
Success.new(yield @value)
|
41
|
+
end
|
42
|
+
|
43
|
+
def fail_map
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_failure
|
48
|
+
Result.new @value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Result < Base
|
53
|
+
def unwrap
|
54
|
+
@value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trither
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lyall Jonathan Di Trapani
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Very simple implementations of Try and Either inspired by Scala
|
56
|
+
email:
|
57
|
+
- lj.ditrapani@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/trither.rb
|
63
|
+
- lib/trither/either.rb
|
64
|
+
- lib/trither/try.rb
|
65
|
+
- lib/trither/version.rb
|
66
|
+
homepage: https://github.com/lj-ditrapani/trither
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.2.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Simple implementations of Try and Either
|
90
|
+
test_files: []
|