1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 07:02:29 +08:00

doc: add go playground demo

This commit is contained in:
dudaodong
2023-07-04 16:31:13 +08:00
parent 584aabdf62
commit 154ec56780
8 changed files with 136 additions and 49 deletions

View File

@@ -13,19 +13,19 @@ type Tuple2[A any, B any] struct {
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/0fD1qfCVwjm
func (t Tuple2[A, B]) Unbox() (A, B) {
return t.FieldA, t.FieldB
}
// NewTuple2 creates a 2 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/3sHVqBQpLYN
func NewTuple2[A any, B any](a A, b B) Tuple2[A, B] {
return Tuple2[A, B]{FieldA: a, FieldB: b}
}
// Zip2 create a slice of Tuple2, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/4ncWJJ77Xio
func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B] {
size := mathutil.Max(len(a), len(b))
@@ -42,7 +42,7 @@ func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B] {
}
// Unzip2 creates a group of slice from a slice of Tuple2.
// Play: todo
// Play: https://go.dev/play/p/KBecr60feXb
func Unzip2[A any, B any](tuples []Tuple2[A, B]) ([]A, []B) {
size := len(tuples)
@@ -65,19 +65,19 @@ type Tuple3[A any, B any, C any] struct {
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/YojLy-id1BS
func (t Tuple3[A, B, C]) Unbox() (A, B, C) {
return t.FieldA, t.FieldB, t.FieldC
}
// NewTuple3 creates a 3 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/FtH2sdCLlCf
func NewTuple3[A any, B any, C any](a A, b B, c C) Tuple3[A, B, C] {
return Tuple3[A, B, C]{FieldA: a, FieldB: b, FieldC: c}
}
// Zip3 create a slice of Tuple3, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/97NgmsTILfu
func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C] {
size := mathutil.Max(len(a), len(b), len(c))
@@ -95,7 +95,7 @@ func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C] {
}
// Unzip3 creates a group of slice from a slice of Tuple3.
// Play: todo
// Play: https://go.dev/play/p/bba4cpAa7KO
func Unzip3[A any, B any, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C) {
size := len(tuples)
@@ -121,19 +121,19 @@ type Tuple4[A any, B any, C any, D any] struct {
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/ACj9YuACGgW
func (t Tuple4[A, B, C, D]) Unbox() (A, B, C, D) {
return t.FieldA, t.FieldB, t.FieldC, t.FieldD
}
// NewTuple4 creates a 4 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/D2EqDz096tk
func NewTuple4[A any, B any, C any, D any](a A, b B, c C, d D) Tuple4[A, B, C, D] {
return Tuple4[A, B, C, D]{FieldA: a, FieldB: b, FieldC: c, FieldD: d}
}
// Zip4 create a slice of Tuple4, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/PEmTYVK5hL4
func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D] {
size := mathutil.Max(len(a), len(b), len(c), len(d))
@@ -152,7 +152,7 @@ func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B,
}
// Unzip4 creates a group of slice from a slice of Tuple4.
// Play: todo
// Play: https://go.dev/play/p/rb8z4gyYSRN
func Unzip4[A any, B any, C any, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D) {
size := len(tuples)
@@ -181,19 +181,19 @@ type Tuple5[A any, B any, C any, D any, E any] struct {
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/GyIyZHjCvoS
func (t Tuple5[A, B, C, D, E]) Unbox() (A, B, C, D, E) {
return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE
}
// NewTuple5 creates a 5 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/2WndmVxPg-r
func NewTuple5[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E) Tuple5[A, B, C, D, E] {
return Tuple5[A, B, C, D, E]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e}
}
// Zip5 create a slice of Tuple5, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/fCAAJLMfBIP
func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E] {
size := mathutil.Max(len(a), len(b), len(c), len(d), len(e))
@@ -215,7 +215,7 @@ func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E)
}
// Unzip5 creates a group of slice from a slice of Tuple5.
// Play: todo
// Play: https://go.dev/play/p/gyl6vKfhqPb
func Unzip5[A any, B any, C any, D any, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E) {
size := len(tuples)
@@ -247,19 +247,19 @@ type Tuple6[A any, B any, C any, D any, E any, F any] struct {
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/FjIHV7lpxmW
func (t Tuple6[A, B, C, D, E, F]) Unbox() (A, B, C, D, E, F) {
return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF
}
// NewTuple6 creates a 6 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/VjqcCwEJZbs
func NewTuple6[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F) Tuple6[A, B, C, D, E, F] {
return Tuple6[A, B, C, D, E, F]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f}
}
// Zip6 create a slice of Tuple6, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/oWPrnUYuFHo
func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F] {
size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f))
@@ -282,7 +282,7 @@ func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D,
}
// Unzip6 creates a group of slice from a slice of Tuple6.
// Play: todo
// Play: https://go.dev/play/p/l41XFqCyh5E
func Unzip6[A any, B any, C any, D any, E any, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F) {
size := len(tuples)
@@ -317,19 +317,19 @@ type Tuple7[A any, B any, C any, D any, E any, F any, G any] struct {
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/R9I8qeDk0zs
func (t Tuple7[A, B, C, D, E, F, G]) Unbox() (A, B, C, D, E, F, G) {
return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF, t.FieldG
}
// NewTuple7 creates a 7 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/dzAgv_Ezub9
func NewTuple7[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G) Tuple7[A, B, C, D, E, F, G] {
return Tuple7[A, B, C, D, E, F, G]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f, FieldG: g}
}
// Zip7 create a slice of Tuple7, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/WUJuo897Egf
func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G] {
size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f), len(g))
@@ -354,7 +354,7 @@ func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C,
}
// Unzip7 creates a group of slice from a slice of Tuple7.
// Play: todo
// Play: https://go.dev/play/p/hws_P1Fr2j3
func Unzip7[A any, B any, C any, D any, E any, F any, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G) {
size := len(tuples)
@@ -392,19 +392,19 @@ type Tuple8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/PRxLBBb4SMl
func (t Tuple8[A, B, C, D, E, F, G, H]) Unbox() (A, B, C, D, E, F, G, H) {
return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF, t.FieldG, t.FieldH
}
// NewTuple8 creates a 8 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/YA9S0rz3dRz
func NewTuple8[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H) Tuple8[A, B, C, D, E, F, G, H] {
return Tuple8[A, B, C, D, E, F, G, H]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f, FieldG: g, FieldH: h}
}
// Zip8 create a slice of Tuple8, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/8V9jWkuJfaQ
func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H] {
size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h))
@@ -430,7 +430,7 @@ func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B,
}
// Unzip8 creates a group of slice from a slice of Tuple8.
// Play: todo
// Play: https://go.dev/play/p/1SndOwGsZB4
func Unzip8[A any, B any, C any, D any, E any, F any, G any, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H) {
size := len(tuples)
@@ -471,19 +471,19 @@ type Tuple9[A any, B any, C any, D any, E any, F any, G any, H any, I any] struc
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/oFJFGTAuOa8
func (t Tuple9[A, B, C, D, E, F, G, H, I]) Unbox() (A, B, C, D, E, F, G, H, I) {
return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF, t.FieldG, t.FieldH, t.FieldI
}
// NewTuple9 creates a 9 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/yS2NGGtZpQr
func NewTuple9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I) Tuple9[A, B, C, D, E, F, G, H, I] {
return Tuple9[A, B, C, D, E, F, G, H, I]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f, FieldG: g, FieldH: h, FieldI: i}
}
// Zip9 create a slice of Tuple9, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/cgsL15QYnfz
func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I] {
size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h), len(i))
@@ -510,7 +510,7 @@ func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A,
}
// Unzip9 creates a group of slice from a slice of Tuple9.
// Play: todo
// Play: https://go.dev/play/p/91-BU_KURSA
func Unzip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I) {
size := len(tuples)
@@ -554,19 +554,19 @@ type Tuple10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J an
}
// Unbox returns values in tuple.
// Play: todo
// Play: https://go.dev/play/p/qfyx3x_X0Cu
func (t Tuple10[A, B, C, D, E, F, G, H, I, J]) Unbox() (A, B, C, D, E, F, G, H, I, J) {
return t.FieldA, t.FieldB, t.FieldC, t.FieldD, t.FieldE, t.FieldF, t.FieldG, t.FieldH, t.FieldI, t.FieldJ
}
// NewTuple10 creates a 10 elemnets tuple from a list of values.
// Play: todo
// Play: https://go.dev/play/p/799qqZg0hUv
func NewTuple10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a A, b B, c C, d D, e E, f F, g G, h H, i I, j J) Tuple10[A, B, C, D, E, F, G, H, I, J] {
return Tuple10[A, B, C, D, E, F, G, H, I, J]{FieldA: a, FieldB: b, FieldC: c, FieldD: d, FieldE: e, FieldF: f, FieldG: g, FieldH: h, FieldI: i, FieldJ: j}
}
// Zip10 create a slice of Tuple10, whose elements are correspond to the given slice elements.
// Play: todo
// Play: https://go.dev/play/p/YSR-2cXnrY4
func Zip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I, j []J) []Tuple10[A, B, C, D, E, F, G, H, I, J] {
size := mathutil.Max(len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h), len(i), len(j))
@@ -595,7 +595,7 @@ func Zip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any]
}
// Unzip10 creates a group of slice from a slice of Tuple10.
// Play: todo
// Play: https://go.dev/play/p/-taQB6Wfre_z
func Unzip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](tuples []Tuple10[A, B, C, D, E, F, G, H, I, J]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I, []J) {
size := len(tuples)