go get github.com/syke99/goptional
package main
import (
"fmt"
"testing"
"github.com/syke99/goptional"
"github.com/stretchr/testify/assert"
)
func transform(val *testType) {
val.greeting = "hello"
}
func printGreeting(val *testType) {
fmt.Println(val.greeting)
}
type testType struct {
greeting string
}
func main() {
// Arrange
tt := testType{}
opt := NewGoptional(&tt)
// Act
opt.Map(transform)
// Assert
assert.Equal(t, "hello", tt.greeting) // asserts true
// Act
opt.Exists(printGreeting) // prints "hello"
}
This library was developed by Quinn Millican (@syke99)