rubyz 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -7
  2. data/lib/either.rb +70 -8
  3. data/lib/rubyz.rb +1 -0
  4. data/lib/rubyz/either.rb +71 -0
  5. metadata +21 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 0077d04851b34ed18938d4387b9b2c59e27c856f
4
- data.tar.gz: b4251d2e5263d63a3e2b548bbb1dda8341e41423
5
- SHA512:
6
- metadata.gz: 7a3a8c250e94026b5f978aafc2f4a2a8151477dc3db83cb355f81d9b331539211d5f833e0f53c57399b2859df505893a5ea255be3b084d3f249b43fc06a6ae93
7
- data.tar.gz: ad27f49042d53e826b4fa488bea295cb47279efbf54caa79ea771c82dae71f3cafcea23db9dd7fdb6fca2289147608920f4b028f313d256d02d4eb8aa3265637
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9fb92f1835a85069402c62c9616ac296710975b2
4
+ data.tar.gz: f1cbe532d4616e45e0e36c6579894d5afd746c02
5
+ SHA512:
6
+ metadata.gz: 914a95fd2f4c7a48fdf4cb428d2f682991cbcc3222a8614a960722f54bbc4352c723496e2f6af271d745998c978fbd19338fd182f908e22045153d7f1f16ff87
7
+ data.tar.gz: 876c072d08667c2e37ce5734bf3086b476be4bc01fc0261081cd775dd08b464f8ecb7e905e95f2b54856bfcd2df5e0fe16540cf6d49c165cd39b44c68c16b410
@@ -1,9 +1,71 @@
1
- class Either
2
- attr_reader :left, :right
3
- def initialize(left, right)
4
- raise ArgumentError.new("Either a right or an left please, not both") if (right != :none and left != :none)
5
- raise ArgumentError.new("Either a right or an left please, please give me one") if (right == :none and left == :none)
6
- @right = right
7
- @left = left
8
- end
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
@@ -0,0 +1 @@
1
+ require_relative 'rubyz/either.rb'
@@ -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.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
- - &id001
38
- - ">="
39
- - !ruby/object:Gem::Version
40
- version: "0"
41
- required_rubygems_version: !ruby/object:Gem::Requirement
42
- requirements:
43
- - *id001
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.7
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
-