rubyz 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/lib/either.rb +70 -8
- data/lib/rubyz.rb +1 -0
- data/lib/rubyz/either.rb +71 -0
- metadata +21 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9fb92f1835a85069402c62c9616ac296710975b2
|
4
|
+
data.tar.gz: f1cbe532d4616e45e0e36c6579894d5afd746c02
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 914a95fd2f4c7a48fdf4cb428d2f682991cbcc3222a8614a960722f54bbc4352c723496e2f6af271d745998c978fbd19338fd182f908e22045153d7f1f16ff87
|
7
|
+
data.tar.gz: 876c072d08667c2e37ce5734bf3086b476be4bc01fc0261081cd775dd08b464f8ecb7e905e95f2b54856bfcd2df5e0fe16540cf6d49c165cd39b44c68c16b410
|
data/lib/either.rb
CHANGED
@@ -1,9 +1,71 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Either
|
2
|
+
|
3
|
+
def self.left(leftval)
|
4
|
+
Left.new(leftval)
|
5
|
+
end
|
6
|
+
def self.right(rightval)
|
7
|
+
Right.new(rightval)
|
8
|
+
end
|
9
|
+
|
10
|
+
def transform(f); self end
|
11
|
+
def left_transform(f); self end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
class Left
|
16
|
+
include Either
|
17
|
+
def initialize(val)
|
18
|
+
@val = val
|
19
|
+
end
|
20
|
+
|
21
|
+
def left?; true end
|
22
|
+
def right?; false end
|
23
|
+
|
24
|
+
def to_a; [] end
|
25
|
+
|
26
|
+
def left_transform(f)
|
27
|
+
Left.new(f.call(@val))
|
28
|
+
end
|
29
|
+
|
30
|
+
def fold (left, right)
|
31
|
+
left.call(@val)
|
32
|
+
end
|
33
|
+
|
34
|
+
def == (other)
|
35
|
+
other.is_a?(Left) && other.leftval == @val
|
36
|
+
end
|
37
|
+
|
38
|
+
# should this be public?
|
39
|
+
def leftval; @val end
|
40
|
+
|
41
|
+
end
|
42
|
+
class Right
|
43
|
+
include Either
|
44
|
+
def initialize(val)
|
45
|
+
@val = val
|
46
|
+
end
|
47
|
+
|
48
|
+
def left?; false end
|
49
|
+
def right?; true end
|
50
|
+
|
51
|
+
def to_a; [@val] end
|
52
|
+
|
53
|
+
def transform(f)
|
54
|
+
Right.new(f.call(@val))
|
55
|
+
end
|
56
|
+
|
57
|
+
def == (other)
|
58
|
+
other.is_a?(Right) && other.val == @val
|
59
|
+
end
|
60
|
+
|
61
|
+
def flatten
|
62
|
+
@val
|
63
|
+
end
|
64
|
+
|
65
|
+
def fold (left, right)
|
66
|
+
right.call(@val)
|
67
|
+
end
|
68
|
+
|
69
|
+
attr_reader :val
|
70
|
+
|
9
71
|
end
|
data/lib/rubyz.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'rubyz/either.rb'
|
data/lib/rubyz/either.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Either
|
2
|
+
|
3
|
+
def self.left(leftval)
|
4
|
+
Left.new(leftval)
|
5
|
+
end
|
6
|
+
def self.right(rightval)
|
7
|
+
Right.new(rightval)
|
8
|
+
end
|
9
|
+
|
10
|
+
def transform(f); self end
|
11
|
+
def left_transform(f); self end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
class Left
|
16
|
+
include Either
|
17
|
+
def initialize(val)
|
18
|
+
@val = val
|
19
|
+
end
|
20
|
+
|
21
|
+
def left?; true end
|
22
|
+
def right?; false end
|
23
|
+
|
24
|
+
def to_a; [] end
|
25
|
+
|
26
|
+
def left_transform(f)
|
27
|
+
Left.new(f.call(@val))
|
28
|
+
end
|
29
|
+
|
30
|
+
def fold (left, right)
|
31
|
+
left.call(@val)
|
32
|
+
end
|
33
|
+
|
34
|
+
def == (other)
|
35
|
+
other.is_a?(Left) && other.leftval == @val
|
36
|
+
end
|
37
|
+
|
38
|
+
# should this be public?
|
39
|
+
def leftval; @val end
|
40
|
+
|
41
|
+
end
|
42
|
+
class Right
|
43
|
+
include Either
|
44
|
+
def initialize(val)
|
45
|
+
@val = val
|
46
|
+
end
|
47
|
+
|
48
|
+
def left?; false end
|
49
|
+
def right?; true end
|
50
|
+
|
51
|
+
def to_a; [@val] end
|
52
|
+
|
53
|
+
def transform(f)
|
54
|
+
Right.new(f.call(@val))
|
55
|
+
end
|
56
|
+
|
57
|
+
def == (other)
|
58
|
+
other.is_a?(Right) && other.val == @val
|
59
|
+
end
|
60
|
+
|
61
|
+
def flatten
|
62
|
+
@val
|
63
|
+
end
|
64
|
+
|
65
|
+
def fold (left, right)
|
66
|
+
right.call(@val)
|
67
|
+
end
|
68
|
+
|
69
|
+
attr_reader :val
|
70
|
+
|
71
|
+
end
|
metadata
CHANGED
@@ -1,52 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyz
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Jessica Kerr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
date: 2013-09-09 00:00:00 Z
|
11
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
|
15
13
|
description: You can do anything in Ruby!
|
16
14
|
email: jessitron@gmail.com
|
17
15
|
executables: []
|
18
|
-
|
19
16
|
extensions: []
|
20
|
-
|
21
17
|
extra_rdoc_files: []
|
22
|
-
|
23
|
-
files:
|
18
|
+
files:
|
24
19
|
- lib/either.rb
|
20
|
+
- lib/rubyz/either.rb
|
21
|
+
- lib/rubyz.rb
|
25
22
|
homepage:
|
26
|
-
licenses:
|
23
|
+
licenses:
|
27
24
|
- CC0
|
28
25
|
metadata: {}
|
29
|
-
|
30
26
|
post_install_message:
|
31
27
|
rdoc_options: []
|
32
|
-
|
33
|
-
require_paths:
|
28
|
+
require_paths:
|
34
29
|
- lib
|
35
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
-
|
38
|
-
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
44
40
|
requirements: []
|
45
|
-
|
46
41
|
rubyforge_project:
|
47
|
-
rubygems_version: 2.0.
|
42
|
+
rubygems_version: 2.0.6
|
48
43
|
signing_key:
|
49
44
|
specification_version: 4
|
50
45
|
summary: like scalaz, but in ruby!
|
51
46
|
test_files: []
|
52
|
-
|