rb-kgy-fp 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 214e8add5a32f22e21fe03db4548810eecbcfc72ba51d6e5abb8f176cf5a9500
4
- data.tar.gz: 63513fb5f942ec686b3fe03c28c27bcb1330b4922ebf51b6e993afb34ecea208
3
+ metadata.gz: bd466fae2751a38d4024523d657941de41c887a63ad6309b90591c28a9992efe
4
+ data.tar.gz: 50b30e436d163ebc5cbaf1f8b7c615c49334063962a8c590dcb9a22f7d6446c6
5
5
  SHA512:
6
- metadata.gz: c935f2bab684f020060d9a30f0aed1b745d3ae0081e247a73ac3c76c454a282934f6ba0d45bbd99dbd1ad55c30659b5de5bf8bfd39b1b934e5e7a66cc57f8e4c
7
- data.tar.gz: 805d4b5766f5afb861c1f5149eddff5dc914badfcaabf3e765533d5aa48cfb6b3037664eeb16fa893d40c7b92b871b3c934101f19855b43c8fb5f9a42a6d8e5e
6
+ metadata.gz: 5d0f8273997f98caad32cbe9d933c758b7573a7c185679ae41b8809830f349aa0b4090379cb0117702d258bb5e07b9bff81296de3c9d7dee32162b9405a1d971
7
+ data.tar.gz: bd2734c9d12abcbefdec6e03b2c3c59352b1ea9a07d4b07c6912c0328eb595f58720f50075c655c3501d6131d9f8c2c5524ee21baebe79646a908e69cf158507
data/lib/rb-kgy-fp/fun.rb CHANGED
@@ -153,7 +153,7 @@ module Fun
153
153
  end
154
154
 
155
155
  def self.curry(&fn)
156
- require "special"
156
+ require_relative "special"
157
157
 
158
158
  req = 1 << 0
159
159
  opt = 1 << 1
@@ -16,6 +16,8 @@ class Either
16
16
 
17
17
  public
18
18
 
19
+ def inspect = to_s
20
+
19
21
  def initialize value
20
22
  @value = value
21
23
  end
@@ -43,9 +45,18 @@ class Either
43
45
  other.right? ? 1 : @value <=> other.value
44
46
  end
45
47
  end
48
+
49
+ def get
50
+ throw RuntimeError
51
+ end
52
+
53
+ def get_left
54
+ throw RuntimeError
55
+ end
46
56
  end
47
57
 
48
58
  class Left < Either
59
+
49
60
  def assoc other
50
61
  other
51
62
  end
@@ -67,7 +78,7 @@ class Left < Either
67
78
  end
68
79
 
69
80
  def to_s
70
- "Left(#{@value})"
81
+ "Left(#{@value.to_s})"
71
82
  end
72
83
 
73
84
  def either(map_left, _)
@@ -77,6 +88,10 @@ class Left < Either
77
88
  def bimap(map_fst, map_snd)
78
89
  Left.new map_fst.(@value)
79
90
  end
91
+
92
+ def get_left
93
+ @value
94
+ end
80
95
  end
81
96
 
82
97
  class Right < Either
@@ -101,7 +116,7 @@ class Right < Either
101
116
  end
102
117
 
103
118
  def to_s
104
- "Right(#{@value})"
119
+ "Right(#{@value.to_s})"
105
120
  end
106
121
 
107
122
  def either(_, map_right)
@@ -111,4 +126,8 @@ class Right < Either
111
126
  def bimap(map_fst, map_snd)
112
127
  of map_snd.(@value)
113
128
  end
129
+
130
+ def get
131
+ @value
132
+ end
114
133
  end
@@ -5,13 +5,12 @@ require_relative '../fun'
5
5
  require_relative '../curry_fun'
6
6
  require_relative '../trait/monad'
7
7
  require_relative '../trait/alternative'
8
+ require 'singleton'
8
9
 
9
10
  class Maybe
10
11
  include Monad, Alternative, Comparable
11
12
 
12
- private
13
-
14
- public
13
+ def inspect = to_s
15
14
 
16
15
  def just?
17
16
  raise Special::UNIMPLEMENTED
@@ -36,14 +35,21 @@ class Maybe
36
35
  def self.empty
37
36
  Nothing.new
38
37
  end
39
-
38
+
40
39
  def consume(other)
41
40
  replace other
42
41
  end
42
+
43
+ def get
44
+ throw RuntimeError
45
+ end
43
46
  end
44
47
 
45
48
  class Just < Maybe
46
49
  attr_reader :value
50
+
51
+ def to_s = "Just(#{@value.to_s})"
52
+
47
53
  def initialize value
48
54
  @value = value
49
55
  end
@@ -80,9 +86,20 @@ class Just < Maybe
80
86
  fn.(@value)
81
87
  end
82
88
 
89
+ def get
90
+ @value
91
+ end
83
92
  end
84
93
 
85
94
  class Nothing < Maybe
95
+ include Singleton
96
+
97
+ def to_s = 'Nothing'
98
+
99
+ def self.of _ = nil
100
+ instance
101
+ end
102
+
86
103
  def just?
87
104
  false
88
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-kgy-fp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Lui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-03 00:00:00.000000000 Z
11
+ date: 2023-09-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby FP lib for self usage. This lib included simple FP functions like
14
14
  Rmada of JS, and different typeclass support as Haskell