diff --git a/map.go b/map.go index 6f93c08..f763fef 100644 --- a/map.go +++ b/map.go @@ -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.IsNothing() { return Nothing[T2]() } diff --git a/optional.go b/optional.go index 53e5d75..1fbc87f 100644 --- a/optional.go +++ b/optional.go @@ -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.IsNothing() { 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: @@ -157,7 +153,7 @@ func (receiver Optional[T]) Get() (T, bool) { // fmt.Println("nothing") // } func (receiver Optional[T]) GetElse(alternative T) T { - if receiver.isnothing() { + if receiver.IsNothing() { return alternative } @@ -189,7 +185,7 @@ func (receiver Optional[T]) GetElse(alternative T) T { // // Output: // // op = opt.Nothing[uint8]() func (receiver Optional[T]) GoString() string { - if receiver.isnothing() { + if receiver.IsNothing() { return fmt.Sprintf("opt.Nothing[%T]()", receiver.value) } @@ -210,7 +206,7 @@ func (receiver Optional[T]) GoString() string { // //@TODO // }) func (receiver Optional[T]) WhenNothing(fn func()) { - if receiver.isnothing() { + if receiver.IsNothing() { fn() } } diff --git a/optional_marshaljson.go b/optional_marshaljson.go index b802834..1444167 100644 --- a/optional_marshaljson.go +++ b/optional_marshaljson.go @@ -18,7 +18,7 @@ func (receiver Optional[T]) MarshalJSON() ([]byte, error) { return nil, erorr.Errorf("opt: cannot marshal something of type %T into JSON because parameterized type is ‘%T’ rather than ‘bool’, ‘string’, or ‘json.Marshaler’", receiver, receiver.value) } - if receiver.isnothing() { + if receiver.IsNothing() { return nil, erorr.Errorf("opt: cannot marshal opt.Nothing[%T]() into JSON", receiver.value) } diff --git a/then.go b/then.go index 7ab54b1..f64db20 100644 --- a/then.go +++ b/then.go @@ -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.IsNothing() { return Nothing[T2]() }