syke99 / goptional

an Option package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

goptional

Go Reference go reportcard License Go version
an Option package for Go

How do I use goptional?

Installation

go get github.com/syke99/goptional

Basic Usage

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"
}

Who?

This library was developed by Quinn Millican (@syke99)

About

an Option package for Go

License:MIT License


Languages

Language:Go 100.0%