REPOSITORY / ScuroNeko/extypes

Compare commits

DIFF REPOSITORY
10 Commits
Author SHA1 Message Date
ScuroNeko 156fa3153c fix: align slice/set equality and harden queue API 2026-03-17 14:37:35 +03:00
ScuroNeko 4232591fcc join 2026-02-19 15:05:01 +03:00
ScuroNeko 6d2ef61432 tuple immutable 2026-02-12 13:46:53 +03:00
ScuroNeko ce8c5b516e some tests 2026-02-09 17:39:41 +03:00
ScuroNeko 8e203ed8d5 some tests 2026-02-09 16:44:16 +03:00
ScuroNeko 06327013fd tuple and code cleanup 2026-02-09 16:31:39 +03:00
ScuroNeko 4ba746956a some testing ang enchancments 2026-02-06 13:46:09 +03:00
ScuroNeko 948ac0a1b0 non comparable slices 2026-02-06 13:18:11 +03:00
ScuroNeko 7d930b6e97 fix Pop method 2026-02-04 12:56:22 +03:00
ScuroNeko 6721658a8e v1.0.2 2026-02-04 12:46:35 +03:00
10 changed files with 698 additions and 177 deletions
+61 -7
View File
@@ -1,4 +1,6 @@
package laniakea
package extypes
import "reflect"
type HashMap[K comparable, V any] map[K]V
@@ -9,9 +11,7 @@ func NewMapFrom[K comparable, V any](m map[K]V) HashMap[K, V] {
}
return out
}
func (m HashMap[K, V]) Len() int {
return len(m)
}
func (m HashMap[K, V]) Len() int { return len(m) }
func (m HashMap[K, V]) Add(key K, val V) HashMap[K, V] {
m[key] = val
return m
@@ -20,9 +20,7 @@ func (m HashMap[K, V]) Remove(key K) HashMap[K, V] {
delete(m, key)
return m
}
func (m HashMap[K, V]) Get(key K) V {
return m[key]
}
func (m HashMap[K, V]) Get(key K) V { return m[key] }
func (m HashMap[K, V]) GetOrDefault(key K, def V) V {
v, ok := m[key]
if !ok {
@@ -34,6 +32,50 @@ func (m HashMap[K, V]) Contains(key K) bool {
_, ok := m[key]
return ok
}
func (m HashMap[K, V]) IndexKey(key K) int {
index := 0
for k, _ := range m {
if k == key {
return index
}
index++
}
return -1
}
func (m HashMap[K, V]) IndexValue(value V) int {
index := 0
for _, v := range m {
if reflect.DeepEqual(value, v) {
return index
}
index++
}
return -1
}
func (m HashMap[K, V]) Keys() []K {
keys := make([]K, 0, m.Len())
for k := range m {
keys = append(keys, k)
}
return keys
}
func (m HashMap[K, V]) Values() []V {
values := make([]V, 0, m.Len())
for _, v := range m {
values = append(values, v)
}
return values
}
func (m HashMap[K, V]) Items() ([]K, []V) {
keys := make(Slice[K], 0, m.Len())
values := make(Slice[V], 0, m.Len())
for k, v := range m {
keys = keys.Push(k)
values = values.Push(v)
}
return keys, values
}
func (m HashMap[K, V]) Filter(f func(K, V) bool) HashMap[K, V] {
out := make(HashMap[K, V])
for k, v := range m {
@@ -44,3 +86,15 @@ func (m HashMap[K, V]) Filter(f func(K, V) bool) HashMap[K, V] {
}
return out
}
func (m HashMap[K, V]) ForEach(f func(K, V)) HashMap[K, V] {
for k, v := range m {
f(k, v)
}
return m
}
func (m HashMap[K, V]) Map(f func(K, V) V) HashMap[K, V] {
for k, v := range m {
m[k] = f(k, v)
}
return m
}
+23
View File
@@ -0,0 +1,23 @@
package extypes
import (
"fmt"
"testing"
)
func BenchmarkHashMap_Add(b *testing.B) {
b.StartTimer()
m := make(HashMap[string, string])
for i := 0; i < b.N; i++ {
m.Add(fmt.Sprint(i), fmt.Sprint(i))
}
b.StopTimer()
}
func BenchmarkGoMap_Add(b *testing.B) {
b.StartTimer()
m := make(map[string]string)
for i := 0; i < b.N; i++ {
m[fmt.Sprint(i)] = fmt.Sprint(i)
}
b.StopTimer()
}
+47 -43
View File
@@ -1,4 +1,4 @@
package laniakea
package extypes
import (
"errors"
@@ -6,66 +6,70 @@ import (
)
var QueueFullErr = errors.New("queue full")
var QueueEmptyErr = errors.New("queue empty")
type Queue[T any] struct {
size uint64
mu sync.RWMutex
queue []T
queue Slice[T]
}
func CreateQueue[T any](size uint64) *Queue[T] {
return &Queue[T]{
queue: make([]T, 0),
size: size,
}
return &Queue[T]{queue: make(Slice[T], 0, size), size: size}
}
func (q *Queue[T]) Len() uint64 {
q.mu.RLock()
defer q.mu.RUnlock()
return uint64(q.queue.Len())
}
func (q *Queue[T]) IsEmpty() bool { return q.Len() == 0 }
func (q *Queue[T]) IsFull() bool { return q.Len() == q.size }
func (q *Queue[T]) Size() uint64 { return q.size }
func (q *Queue[T]) Enqueue(el T) error {
if q.IsFull() {
q.mu.Lock()
defer q.mu.Unlock()
if uint64(len(q.queue)) == q.size {
return QueueFullErr
}
q.queue = append(q.queue, el)
q.queue = q.queue.Push(el)
return nil
}
func (q *Queue[T]) Peak() T {
q.mu.RLock()
defer q.mu.RUnlock()
return q.queue[0]
}
func (q *Queue[T]) Dequeue() (T, error) {
q.mu.Lock()
defer q.mu.Unlock()
func (q *Queue[T]) IsEmpty() bool {
return q.Length() == 0
}
func (q *Queue[T]) IsFull() bool {
return q.Length() == q.size
}
func (q *Queue[T]) Length() uint64 {
q.mu.RLock()
defer q.mu.RUnlock()
return uint64(len(q.queue))
}
func (q *Queue[T]) Dequeue() T {
q.mu.RLock()
el := q.queue[0]
q.mu.RUnlock()
if q.Length() == 1 {
q.mu.Lock()
q.queue = make([]T, 0)
q.mu.Unlock()
return el
var zero T
if len(q.queue) == 0 {
return zero, QueueEmptyErr
}
q.mu.Lock()
q.queue = q.queue[1:]
q.mu.Unlock()
return el
el := q.queue[0]
copy(q.queue, q.queue[1:])
q.queue[len(q.queue)-1] = zero
q.queue = q.queue[:len(q.queue)-1]
return el, nil
}
func (q *Queue[T]) Raw() []T {
return q.queue
func (q *Queue[T]) Peak() (T, error) {
q.mu.RLock()
defer q.mu.RUnlock()
var zero T
if len(q.queue) == 0 {
return zero, QueueEmptyErr
}
return q.queue[0], nil
}
func (q *Queue[T]) Raw() Slice[T] {
q.mu.RLock()
defer q.mu.RUnlock()
return NewSliceFrom(q.queue)
}
+129
View File
@@ -0,0 +1,129 @@
package extypes
import (
"log"
"testing"
)
func ExampleCreateQueue() {
q := CreateQueue[int](16)
err := q.Enqueue(1)
if err != nil {
panic(err)
}
i, err := q.Dequeue() // <- Here we got 1
if err != nil {
panic(err)
}
log.Println(i)
}
func BenchmarkQueue_Enqueue(b *testing.B) {
b.StartTimer()
q := CreateQueue[int](uint64(b.N))
for i := 0; i < b.N; i++ {
if err := q.Enqueue(i); err != nil {
b.Fatal(err)
}
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkQueue_Dequeue(b *testing.B) {
q := CreateQueue[int](uint64(b.N))
for i := 0; i < b.N; i++ {
if err := q.Enqueue(i); err != nil {
b.Fatal(err)
}
}
b.StartTimer()
for i := 0; i < b.N; i++ {
if _, err := q.Dequeue(); err != nil {
b.Fatal(err)
}
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkQueue_EnqueueDequeue(b *testing.B) {
b.StartTimer()
q := CreateQueue[int](uint64(b.N))
for i := 0; i < b.N; i++ {
if err := q.Enqueue(i); err != nil {
b.Fatal(err)
}
}
for i := 0; i < b.N; i++ {
if _, err := q.Dequeue(); err != nil {
b.Fatal(err)
}
}
b.StopTimer()
b.ReportAllocs()
}
func TestQueue_Empty(t *testing.T) {
q := CreateQueue[int](1)
if _, err := q.Peak(); err != QueueEmptyErr {
t.Fatalf("Peak() error = %v, want %v", err, QueueEmptyErr)
}
if _, err := q.Dequeue(); err != QueueEmptyErr {
t.Fatalf("Dequeue() error = %v, want %v", err, QueueEmptyErr)
}
}
func TestQueue_BasicOperations(t *testing.T) {
q := CreateQueue[int](2)
if err := q.Enqueue(1); err != nil {
t.Fatal(err)
}
if err := q.Enqueue(2); err != nil {
t.Fatal(err)
}
if err := q.Enqueue(3); err != QueueFullErr {
t.Fatalf("Enqueue() error = %v, want %v", err, QueueFullErr)
}
head, err := q.Peak()
if err != nil {
t.Fatal(err)
}
if head != 1 {
t.Fatalf("Peak() = %d, want 1", head)
}
first, err := q.Dequeue()
if err != nil {
t.Fatal(err)
}
if first != 1 {
t.Fatalf("Dequeue() = %d, want 1", first)
}
second, err := q.Dequeue()
if err != nil {
t.Fatal(err)
}
if second != 2 {
t.Fatalf("Dequeue() = %d, want 2", second)
}
}
func TestQueue_RawReturnsCopy(t *testing.T) {
q := CreateQueue[int](2)
if err := q.Enqueue(1); err != nil {
t.Fatal(err)
}
raw := q.Raw()
raw[0] = 99
head, err := q.Peak()
if err != nil {
t.Fatal(err)
}
if head != 1 {
t.Fatalf("Peak() = %d, want 1", head)
}
}
+117
View File
@@ -0,0 +1,117 @@
package extypes
import (
"fmt"
"reflect"
"strings"
)
type Set[T any] []T
func NewSetFrom[T any](slice []T) Set[T] {
s := make(Set[T], 0)
for _, v := range slice {
if s.Index(v) >= 0 {
continue
}
s = append(s, v)
}
return s
}
func (s Set[T]) Len() int { return len(s) }
func (s Set[T]) Cap() int { return cap(s) }
func (s Set[T]) Get(index int) T { return s[index] }
func (s Set[T]) Last() T { return s.Get(s.Len() - 1) }
func (s Set[T]) First() T { return s.Get(0) }
func (s Set[T]) Index(el T) int {
for i := range s {
if reflect.DeepEqual(s[i], el) {
return i
}
}
return -1
}
func (s Set[T]) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s Set[T]) Add(v T) Set[T] {
index := s.Index(v)
if index >= 0 {
return s
}
return append(s, v)
}
func (s Set[T]) Pop(index int) Set[T] {
if index == 0 {
return s[1:]
}
out := make(Set[T], s.Len()-1)
copy(out, s[:index])
copy(out[index:], s[index+1:])
return out
}
func (s Set[T]) Remove(el T) Set[T] {
index := s.Index(el)
if index == -1 {
return s
}
return s.Pop(index)
}
func (s Set[T]) Equal(s2 Set[T]) bool {
if s.Len() != s2.Len() {
return false
}
for i := range s {
if !reflect.DeepEqual(s[i], s2[i]) {
return false
}
}
return true
}
func (s Set[T]) ToSlice() Slice[T] { return NewSliceFrom(s) }
func (s Set[T]) ToTuple() Tuple[T] { return NewTupleFrom(s) }
func (s Set[T]) ToArray() []T {
out := make([]T, len(s))
copy(out, s)
return out
}
func (s Set[T]) ToAnyArray() []any {
out := make([]any, len(s))
for i, v := range s {
out[i] = v
}
return out
}
func (s Set[T]) Filter(f func(e T) bool) Set[T] {
out := make(Set[T], 0)
for _, v := range s {
if f(v) {
out = append(out, v)
}
}
return out
}
func (s Set[T]) ForEach(f func(int, T)) Set[T] {
for i, v := range s {
f(i, v)
}
return s
}
// Map is mutable func
func (s Set[T]) Map(f func(e T) T) Set[T] {
for i, v := range s {
s[i] = f(v)
}
return s
}
func (s Set[T]) Join(sep string) string {
st := make([]string, len(s))
for i, v := range s {
st[i] = fmt.Sprintf("%v", v)
}
return strings.Join(st, sep)
}
+31
View File
@@ -0,0 +1,31 @@
package extypes
import "testing"
func TestSet(t *testing.T) {
s1 := make(Set[int], 0)
s2 := make(Set[int], 0)
s1 = s1.Add(1)
s1 = s1.Add(2)
s1 = s1.Add(2)
s2 = s2.Add(1)
s2 = s2.Add(2)
if !s1.Equal(s2) {
t.Error("s1 and s2 not equal")
}
}
func TestSet_EqualIgnoresCapacity(t *testing.T) {
s1 := make(Set[int], 2, 2)
s2 := make(Set[int], 2, 4)
s1[0], s1[1] = 1, 2
s2[0], s2[1] = 1, 2
if !s1.Equal(s2) {
t.Error("s1 and s2 not equal")
}
}
+63 -127
View File
@@ -1,62 +1,41 @@
package laniakea
package extypes
import "slices"
import (
"fmt"
"reflect"
"strings"
)
type Slice[T comparable] []T
type Slice[T any] []T
func NewSliceFrom[T comparable](slice []T) Slice[T] {
func NewSliceFrom[T any](slice []T) Slice[T] {
s := make(Slice[T], len(slice))
copy(s, slice)
return s
}
func (s Slice[T]) Len() int {
return len(s)
}
func (s Slice[T]) Cap() int {
return cap(s)
}
func (s Slice[T]) Get(index int) T {
return s[index]
}
func (s Slice[T]) Last() T {
return s.Get(s.Len() - 1)
}
func (s Slice[T]) Index(el T) int {
return slices.Index(s, el)
}
func (s Slice[T]) Len() int { return len(s) }
func (s Slice[T]) Cap() int { return cap(s) }
func (s Slice[T]) Get(index int) T { return s[index] }
func (s Slice[T]) Last() T { return s.Get(s.Len() - 1) }
func (s Slice[T]) First() T { return s.Get(0) }
// Swap is mutable func
func (s Slice[T]) Swap(i, j int) Slice[T] {
s[i], s[j] = s[j], s[i]
return s
}
func (s Slice[T]) Filter(f func(e T) bool) Slice[T] {
out := make(Slice[T], 0)
for _, v := range s {
if f(v) {
out = append(out, v)
func (s Slice[T]) Index(el T) int {
for i := range s {
if reflect.DeepEqual(s[i], el) {
return i
}
}
return out
}
func (s Slice[T]) Map(f func(e T) T) Slice[T] {
out := make(Slice[T], s.Len())
for i, v := range s {
out[i] = f(v)
}
return out
return -1
}
func (s Slice[T]) Push(e T) Slice[T] { return append(s, e) }
func (s Slice[T]) Pop(index int) Slice[T] {
if index == 0 {
return s[1:]
}
out := make(Slice[T], s.Len()-index)
for i, e := range s {
if i == index {
continue
}
out[i] = e
}
out := make(Slice[T], s.Len()-1)
copy(out, s[:index])
copy(out[index:], s[index+1:])
return out
}
func (s Slice[T]) Remove(el T) Slice[T] {
@@ -66,8 +45,23 @@ func (s Slice[T]) Remove(el T) Slice[T] {
}
return s.Pop(index)
}
func (s Slice[T]) Push(e T) Slice[T] {
return append(s, e)
// Swap is mutable func
func (s Slice[T]) Swap(i, j int) Slice[T] {
s[i], s[j] = s[j], s[i]
return s
}
func (s Slice[T]) Equal(s2 Slice[T]) bool {
if s.Len() != s2.Len() {
return false
}
for i := range s {
if !reflect.DeepEqual(s[i], s2[i]) {
return false
}
}
return true
}
func (s Slice[T]) ToArray() []T {
@@ -82,74 +76,11 @@ func (s Slice[T]) ToAnyArray() []any {
}
return out
}
func (s Slice[T]) ToSet() Set[T] { return NewSetFrom(s) }
func (s Slice[T]) ToTuple() Tuple[T] { return NewTupleFrom(s) }
// ForEach is mutable func
func (s Slice[T]) ForEach(f func(e T) T) Slice[T] {
for i, v := range s {
s[i] = f(v)
}
return s
}
type Set[T comparable] []T
func NewSetFrom[T comparable](slice []T) Set[T] {
s := make(Set[T], 0)
for _, v := range slice {
if s.Index(v) >= 0 {
continue
}
s = append(s, v)
}
return s
}
func (s Set[T]) Len() int {
return len(s)
}
func (s Set[T]) Cap() int {
return cap(s)
}
func (s Set[T]) Get(index int) T {
return s[index]
}
func (s Set[T]) Last() T {
return s[s.Len()-1]
}
func (s Set[T]) Index(el T) int {
return slices.Index(s, el)
}
func (s Set[T]) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s Set[T]) Add(v T) Set[T] {
index := s.Index(v)
if index >= 0 {
return s
}
return append(s, v)
}
func (s Set[T]) Pop(index int) Set[T] {
if index == 0 {
return s[1:]
}
out := make(Set[T], s.Len()-index)
for i, e := range s {
if i == index {
continue
}
out[i] = e
}
return out
}
func (s Set[T]) Remove(el T) Set[T] {
index := s.Index(el)
if index == -1 {
return s
}
return s.Pop(index)
}
func (s Set[T]) Filter(f func(e T) bool) Set[T] {
out := make(Set[T], 0)
func (s Slice[T]) Filter(f func(e T) bool) Slice[T] {
out := make(Slice[T], 0)
for _, v := range s {
if f(v) {
out = append(out, v)
@@ -157,20 +88,25 @@ func (s Set[T]) Filter(f func(e T) bool) Set[T] {
}
return out
}
func (s Set[T]) ToSlice() Slice[T] {
out := make(Slice[T], s.Len())
copy(out, s)
return out
}
func (s Set[T]) ToArray() []T {
out := make([]T, len(s))
copy(out, s)
return out
}
func (s Set[T]) ToAnyArray() []any {
out := make([]any, len(s))
func (s Slice[T]) ForEach(f func(int, T)) Slice[T] {
for i, v := range s {
out[i] = v
f(i, v)
}
return out
return s
}
// Map is mutable func
func (s Slice[T]) Map(f func(e T) T) Slice[T] {
for i, v := range s {
s[i] = f(v)
}
return s
}
func (s Slice[T]) Join(sep string) string {
st := make([]string, len(s))
for i, v := range s {
st[i] = fmt.Sprintf("%v", v)
}
return strings.Join(st, sep)
}
+104
View File
@@ -0,0 +1,104 @@
package extypes
import (
"fmt"
"testing"
)
type A struct {
i int
b bool
s string
}
func TestSlice_Index(t *testing.T) {
s := make(Slice[int], 10)
for i := 0; i < 10; i++ {
s[i] = i + 1
}
if s.Index(0) != -1 {
t.Errorf("s.Index(0) != -1")
}
if s.Index(5) != 4 {
t.Errorf("s.Index(5) != 4")
}
s2 := make(Slice[A], 5)
for i := 0; i < 5; i++ {
s2[i] = A{i + 1, false, fmt.Sprint(i)}
}
if s2.Index(A{2, false, "1"}) != 1 {
t.Errorf("s2 wrong index")
}
}
func TestSlice_Equal(t *testing.T) {
a1 := make(Slice[int], 10)
a2 := make(Slice[int], 10)
a3 := make(Slice[int], 5)
for i := 0; i < 10; i++ {
a1[i] = i
a2[i] = i + 1
}
for i := 0; i < 5; i++ {
a3[i] = i
}
if a1.Equal(a2) {
t.Errorf("a1 == a2")
}
if a1.Equal(a3) {
t.Errorf("a1 == a3")
}
if a2.Equal(a3) {
t.Errorf("a2 == a3")
}
}
func TestSlice_EqualIgnoresCapacity(t *testing.T) {
a1 := make(Slice[int], 2, 2)
a2 := make(Slice[int], 2, 4)
a1[0], a1[1] = 1, 2
a2[0], a2[1] = 1, 2
if !a1.Equal(a2) {
t.Errorf("a1 != a2")
}
}
func TestSlice_Pop(t *testing.T) {
a1 := make(Slice[int], 10)
a2 := make(Slice[int], 9)
for i := 0; i < 10; i++ {
a1[i] = i
}
for i := 0; i < 9; i++ {
a2[i] = i
}
a1 = a1.Pop(a1.Len() - 1)
if a1.Len() != 9 {
t.Errorf("a1.Len() != 9")
}
if !a1.Equal(a2) {
t.Errorf("a1 != a2")
}
}
func TestSlice_PopFrontEqual(t *testing.T) {
a1 := make(Slice[int], 3, 5)
a2 := make(Slice[int], 2, 2)
a1[0], a1[1], a1[2] = 0, 1, 2
a2[0], a2[1] = 1, 2
a1 = a1.Pop(0)
if !a1.Equal(a2) {
t.Errorf("a1 != a2")
}
}
+74
View File
@@ -0,0 +1,74 @@
package extypes
import (
"encoding/json"
"fmt"
"reflect"
"strings"
)
type Tuple[T any] struct {
s Slice[T]
}
func NewTupleFrom[T any](src []T) Tuple[T] { return Tuple[T]{src} }
func NewTuple[T any]() Tuple[T] { return Tuple[T]{make(Slice[T], 0)} }
func (t Tuple[T]) Len() int { return t.s.Len() }
func (t Tuple[T]) Cap() int { return t.s.Cap() }
func (t Tuple[T]) Get(index int) T { return t.s.Get(index) }
func (t Tuple[T]) Equal(t2 Tuple[T]) bool {
if t.Len() != t2.Len() {
return false
}
for i := range t.s {
if !reflect.DeepEqual(t.s[i], t2.s[i]) {
return false
}
}
return true
}
func (t Tuple[T]) ToArray() []T {
out := make([]T, t.Len())
copy(out, t.s)
return out
}
func (t Tuple[T]) ToAnyArray() []any {
out := make([]any, t.Len())
for i, v := range t.s {
out[i] = v
}
return out
}
func (t Tuple[T]) ToSet() Set[T] { return NewSetFrom(t.s) }
func (t Tuple[T]) ToSlice() Slice[T] { return NewSliceFrom(t.s) }
func (t Tuple[T]) Filter(f func(e T) bool) Tuple[T] {
out := make(Slice[T], 0)
for _, v := range t.s {
if f(v) {
out = append(out, v)
}
}
t.s = out
return t
}
func (t Tuple[T]) ForEach(f func(int, T)) Tuple[T] {
for i, v := range t.s {
f(i, v)
}
return t
}
func (t Tuple[T]) Join(sep string) string {
st := make([]string, len(t.s))
for i, v := range t.s {
st[i] = fmt.Sprintf("%v", v)
}
return strings.Join(st, sep)
}
func (t Tuple[T]) String() string { return fmt.Sprint(t.s) }
func (t *Tuple[T]) UnmarshalJSON(data []byte) error { return json.Unmarshal(data, &t.s) }
func (t Tuple[T]) MarshalJSON() ([]byte, error) { return json.Marshal(t.s) }
+49
View File
@@ -0,0 +1,49 @@
package extypes
import (
"encoding/json"
"testing"
)
func TestTuple(t *testing.T) {
t1 := NewTupleFrom([]int{1, 2, 3})
t2 := NewTupleFrom([]int{1, 2, 3})
if !t1.Equal(t2) {
t.Error("t1 and t2 should be equal")
}
}
func TestTuple_MarshalJSON(t *testing.T) {
t1 := NewTupleFrom([]int{1, 2, 3})
data, err := json.Marshal(t1)
if err != nil {
t.Fatal(err)
}
s := "[1,2,3]"
if string(data) != s {
t.Error("t1 and t2 should be equal")
}
}
func TestTuple_UnmarshalJSON(t *testing.T) {
s := "[1,2,3]"
t1 := NewTuple[int]()
err := json.Unmarshal([]byte(s), &t1)
if err != nil {
t.Fatal(err)
}
t2 := NewTupleFrom([]int{1, 2, 3})
t.Log(t1, t2)
if !t1.Equal(t2) {
t.Error("t1 and t2 should be equal")
}
st1 := struct {
A int `json:"a"`
B Tuple[int] `json:"b"`
}{}
s2 := `{"a":1,"b":[1,2,3]}`
if err := json.Unmarshal([]byte(s2), &st1); err != nil {
t.Fatal(err)
}
t.Log(st1)
}