Skip to content

Use generic optional type instead of pointers for changeset #3

Description

@hlubek

Bulding pointers to pointers can be tricky and need some extra lines of code.

We could use a generic Optional type behind some command flag:

type Optional[T any] struct {
	Valid bool
	Value T
}

func NewValidOptional[T any](value T) Optional[T] {
	return Optional[T]{
		Valid: true,
		Value: value,
	}
}

func NewEmptyOptional[T any]() Optional[T] {
	return Optional[T]{
		Valid: false,
	}
}

func init() {
	v1 := NewValidOptional(uuid.Nil)
	v2 := NewEmptyOptional[uuid.UUID]()
	
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions