File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,13 @@ func Empty[T comparable]() *Optional[T] {
3131 return opt
3232}
3333
34+ // Clone creates and returns a copy of this optional value.
35+ func (opt * Optional [T ]) Clone () * Optional [T ] {
36+ clone := new (Optional [T ])
37+ clone .val = opt .val
38+ return clone
39+ }
40+
3441// Equals indicates whether some other value is equals to this Optional.
3542func (opt * Optional [T ]) Equals (other any ) bool {
3643 if opt == other {
Original file line number Diff line number Diff line change @@ -100,6 +100,20 @@ func TestOptional(t *testing.T) {
100100 a .EqualNow (opt .OrElse ("default" ), "some text" )
101101}
102102
103+ func TestOptionalClone (t * testing.T ) {
104+ a := assert .New (t )
105+
106+ opt := optional .Empty [string ]()
107+ cpy := opt .Clone ()
108+ a .NotEqualNow (opt , cpy )
109+ a .EqualNow (cpy .IsEmpty (), cpy .IsEmpty ())
110+
111+ opt = optional .Of ("test" )
112+ cpy = opt .Clone ()
113+ a .NotEqualNow (opt , cpy )
114+ a .EqualNow (cpy .GetPanic (), opt .GetPanic ())
115+ }
116+
103117func TestOptionalEquals (t * testing.T ) {
104118 a := assert .New (t )
105119
You can’t perform that action at this time.
0 commit comments