@@ -2,9 +2,11 @@ module Rs
22 # https://doc.rust-lang.org/std/option/index.html
33 # https://doc.rust-lang.org/std/option/enum.Option.html
44 # https://doc.rust-lang.org/src/core/option.rs.html
5- class Option
5+ class Option [V]
66 class TypeError < StandardError
7- def initialize : (untyped value_type) -> void
7+ # wanted Class[V]
8+ # no need declare new type V
9+ def initialize : [V] (T[V] value_type) -> void
810 end
911
1012 class TypeNilClass < StandardError
@@ -19,80 +21,93 @@ module Rs
1921 class UnwrapNone < StandardError
2022 end
2123
22- def is_some : () -> untyped
24+ def is_some : () -> bool
2325
24- def is_some_and : () { (? ) -> untyped } -> ( untyped | false)
26+ def is_some_and : () { (V ) -> bool } -> bool
2527
26- def is_none : () -> untyped
28+ def is_none : () -> bool
2729
28- def is_none_or : () { (? ) -> untyped } -> (true | untyped )
30+ def is_none_or : () { (V ) -> bool } -> bool
2931
30- def expect : (untyped msg) -> untyped
32+ def expect : (String msg) -> V
3133
32- def unwrap : () -> untyped
34+ def unwrap : () -> V
3335
34- def unwrap_or : (untyped default) -> untyped
36+ def unwrap_or : (V default) -> V
3537
36- def unwrap_or_else : () { (? ) -> untyped } -> untyped
38+ def unwrap_or_else : () { () -> V } -> V
3739
38- def map : ( untyped value_type) { (? ) -> untyped } -> untyped
40+ def map : [U] (T[U] value_type) { (V ) -> U } -> Option[U]
3941
40- def tap : () { (? ) -> untyped } -> self
42+ def tap : () { (V ) -> bool } -> self
4143
42- def map_or : ( untyped default) { (? ) -> untyped } -> untyped
44+ def map_or : [U] (U default) { (V ) -> U } -> U
4345
44- def map_or_else : (untyped default) { (?) -> untyped } -> untyped
46+ # work
47+ # type int_or_string = Integer | String
48+ #
49+ # not work
50+ # type ld = lambda { () -> U }
51+ # type ld = lambda { -> U }
52+ # type pd = Proc(U)
53+ #
54+ # want, crystal like
55+ # type D = -> U
56+ # type F = (V) -> U
57+ # type F = V -> U
58+ def map_or_else : [U] (Proc default) { (V) -> U } -> U
4559
46- def ok_or : ( untyped error) -> untyped
60+ def ok_or : [E] (E error) -> Rs::Result[V, E]
4761
48- def ok_or_else : () { (? ) -> untyped } -> untyped
62+ def ok_or_else : [E] () { () -> E } -> Rs::Result[V, E]
4963
50- def and : ( untyped other) -> untyped
64+ def and : [U] (Option[U] other) -> Option[U]
5165
52- def and_then : ( untyped value_type) { (? ) -> untyped } -> untyped
66+ def and_then : [U] (T[U] value_type) { (V ) -> Option[U] } -> Option[U]
5367
54- def select : () { (? ) -> untyped } -> untyped
68+ def select : () { (V ) -> bool } -> bool
5569
56- def or : (untyped other) -> ( self | untyped )
70+ def or : (self other) -> self
5771
58- def or_else : () { (? ) -> untyped } -> ( self | untyped )
72+ def or_else : () { () -> self } -> self
5973
60- def xor : (untyped other) -> untyped
74+ def xor : (self other) -> self
6175
62- def self.from : ( untyped value_type) { (? ) -> untyped } -> untyped
76+ def self.from : [V] (T[V] value_type) { () -> V } -> self
6377
64- def self.from? : ( untyped value_type) { (? ) -> untyped } -> untyped
78+ def self.from? : [V] (T[V] value_type) { () -> V? } -> self
6579
66- def self.from! : ( untyped value_type) { (? ) -> untyped } -> untyped
80+ def self.from! : [V] (T[V] value_type) { () -> V } -> self
6781 end
6882end
6983
70- class Some < Rs::Option
71- @value: untyped
84+ class Some [V] < Rs::Option[V]
85+ @value: V
7286
73- @value_type: untyped
87+ # wanted Class[V]
88+ @value_type: T[V]
7489
75- attr_reader value_type: untyped
90+ attr_reader value_type: T[V]
7691
77- def self.[] : ( untyped value_type) { (? ) -> untyped } -> untyped
92+ def self.[] : [V] (T[V] value_type) { () -> V } -> self
7893
7994 def inspect : () -> ::String
8095
81- def == : (untyped other) -> untyped
96+ def == : (Rs::Option[V] other) -> bool
8297
83- def initialize : (untyped value) -> void
98+ def initialize : (V value) -> void
8499end
85100
86- class None < Rs::Option
87- @value_type: untyped
101+ class None [V] < Rs::Option[V]
102+ @value_type: T[V]
88103
89- attr_reader value_type: untyped
104+ attr_reader value_type: T[V]
90105
91- def self.[] : ( untyped value_type) -> untyped
106+ def self.[] : [V] (T[V] value_type) -> self
92107
93108 def inspect : () -> ::String
94109
95- def == : (untyped other) -> untyped
110+ def == : (Rs::Option[V] other) -> bool
96111
97- def initialize : (?untyped value_type) -> void
112+ def initialize : (?T[V] value_type) -> void
98113end
0 commit comments