Created
August 17, 2022 14:14
-
-
Save kaskichandrakant/cc671b9bc5d4f53bad538de0c392853f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type printable[T any] struct { | |
data []any | |
} | |
func (p *printable[T]) Set(value []any) { | |
p.data = value | |
} | |
func (p *printable[T]) printAll() { | |
for i := 0; i < len(p.data); i++ { | |
fmt.Println(p.data[i]) | |
} | |
} | |
func New[T any]() printable[T] { | |
p := printable[T]{} | |
return p | |
} | |
type test struct { | |
Name string | |
} | |
func main() { | |
// -----------types-------- | |
tests := New[[]test]() | |
tests.Set([]any{test{Name: "test"}, test{Name: "test2"}}) | |
tests.printAll() | |
// -----------ints-------- | |
ints := New[[]int]() | |
ints.Set([]any{1, 2, 3, 4, 5}) | |
ints.printAll() | |
// -----------string-------- | |
strings := New[[]string]() | |
strings.Set([]any{"te1", "te2", "te3", "te4", "te5"}) | |
strings.printAll() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment