github.com/hsfzxjy/dgo/go@v0.2.0/marker.go (about)

     1  package dgo
     2  
     3  type Optional[T any] struct {
     4  	Value                 T
     5  	isSome                bool
     6  	_dgo_optional_marker_ struct{} //lint:ignore U1000 A special marker
     7  }
     8  
     9  func Some[T any](value T) Optional[T] { return Optional[T]{Value: value, isSome: true} }
    10  func None[T any]() Optional[T]        { return Optional[T]{} }
    11  
    12  func (o *Optional[T]) IsSome() bool { return o.isSome }
    13  func (o *Optional[T]) IsNone() bool { return !o.isSome }
    14  func (o *Optional[T]) Clear() {
    15  	var zero T
    16  	o.Value = zero
    17  	o.isSome = false
    18  }
    19  func (o *Optional[T]) Set(value T) {
    20  	o.Value = value
    21  	o.isSome = true
    22  }
    23  func (o *Optional[T]) SetZero() {
    24  	var zero T
    25  	o.Value = zero
    26  	o.isSome = true
    27  }