Compare commits

..

No commits in common. "3f808e974991c017f323157c718e23d91ae1a17b" and "58bf264aa928538a63daac016d8480ac9d0355c2" have entirely different histories.

5 changed files with 5 additions and 47 deletions

2
map.go
View File

@ -39,7 +39,7 @@ package opt
//
// // result2 == opt.Nothing[int]()
func Map[T1 any, T2 any](op Optional[T1], fn func(T1)T2) Optional[T2] {
if op.isnothing() {
if !op.something {
return Nothing[T2]()
}

View File

@ -107,7 +107,7 @@ func Something[T any](value T) Optional[T] {
//
// op3 = op3.Filter(fn)
func (receiver Optional[T]) Filter(fn func(T)bool) Optional[T] {
if receiver.isnothing() {
if !receiver.something {
return Nothing[T]()
}
@ -118,10 +118,6 @@ func (receiver Optional[T]) Filter(fn func(T)bool) Optional[T] {
return receiver
}
func (receiver Optional[T]) isnothing() bool {
return !receiver.something
}
// Get returns the value inside of the optional-type if it is holding something.
//
// Example usage:
@ -166,7 +162,7 @@ func (receiver Optional[T]) Get() (T, bool) {
// // Output:
// // op = opt.Nothing[uint8]()
func (receiver Optional[T]) GoString() string {
if receiver.isnothing() {
if !receiver.something {
return fmt.Sprintf("opt.Nothing[%T]()", receiver.value)
}
@ -187,7 +183,7 @@ func (receiver Optional[T]) GoString() string {
// //@TODO
// })
func (receiver Optional[T]) WhenNothing(fn func()) {
if receiver.isnothing() {
if !receiver.something {
fn()
}
}

View File

@ -44,22 +44,3 @@ func TestOptional_MarshalJSON_bool(t *testing.T) {
}
}
}
func TestOptional_MarshalJSON_bool_fail(t *testing.T) {
var nothing opt.Optional[bool]
actualBytes, err := nothing.MarshalJSON()
if nil == err {
t.Error("Expected an error but did not actually get one.")
t.Logf("ACTUAL: %q", actualBytes)
t.Logf("ERROR: (%T) %s", err, err)
return
}
if nil != actualBytes {
t.Error("Expected not bytes but actually get some.")
t.Logf("ACTUAL: %q", actualBytes)
t.Logf("ERROR: (%T) %s", err, err)
return
}
}

View File

@ -103,22 +103,3 @@ func TestOptional_MarshalJSON_string(t *testing.T) {
}
}
}
func TestOptional_MarshalJSON_string_fail(t *testing.T) {
var nothing opt.Optional[string]
actualBytes, err := nothing.MarshalJSON()
if nil == err {
t.Error("Expected an error but did not actually get one.")
t.Logf("ACTUAL: %q", actualBytes)
t.Logf("ERROR: (%T) %s", err, err)
return
}
if nil != actualBytes {
t.Error("Expected not bytes but actually get some.")
t.Logf("ACTUAL: %q", actualBytes)
t.Logf("ERROR: (%T) %s", err, err)
return
}
}

View File

@ -36,7 +36,7 @@ package opt
//
// // result2 == opt.Nothing[byte]()
func Then[T1 any, T2 any](op Optional[T1], fn func(T1)Optional[T2]) Optional[T2] {
if op.isnothing() {
if !op.something {
return Nothing[T2]()
}