Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use generics for Pointer func #316

Merged
merged 1 commit into from
Mar 9, 2024

Conversation

Tinyblargon
Copy link
Collaborator

Removed the type specific pointer creation functions and replaced it with one that uses generics.
Created the util package in the internal folder as the integration tests where using the old pointer functions. Putting it in internal ensures it can't be imported by a third party project.

Before:

func PointerString(text string) *string {
	return &text
}

// Creates a pointer to an int
func PointerInt(number int) *int {
	return &number
}

// Creates a pointer to a bool
func PointerBool(boolean bool) *bool {
	return &boolean
}

After:

func Pointer[T any](item T) *T {
	return &item
}

@Tinyblargon Tinyblargon self-assigned this Mar 6, 2024
@Tinyblargon Tinyblargon merged commit 9c58332 into Telmate:master Mar 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants