tuple

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package tuple provides definition of generic n-ary tuples, from T2 to T10.

Quick Start

package main

import (
	"fmt"
	"github.com/bytedance/gg/collection/tuple"
)

func main() {
	addr := tuple.Make2("localhost", 8080)
	fmt.Printf("%s:%d\n", addr.First, addr.Second)
	// Output:
	// localhost:8080
 }

If you have a need for n-ary (where n > 10) tuple, please file an issue.

Example
addr := Make2("localhost", 8080)
fmt.Printf("%s:%d\n", addr.First, addr.Second) // localhost:8080

s := Zip2([]string{"red", "green", "blue"}, []int{14, 15, 16})
for _, v := range s {
	fmt.Printf("%s:%d\n", v.First, v.Second)
}

fmt.Println(s.Unzip()) // ["red", "green", "blue"] [14, 15, 16]
Output:

localhost:8080
red:14
green:15
blue:16
[red green blue] [14 15 16]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

type Pair[V1, V2 any] T2[V1, V2]

type S2

type S2[V1, V2 any] []T2[V1, V2]

S2 is a slice of 2-ary tuple.

func Zip2

func Zip2[V1, V2 any](s1 []V1, s2 []V2) S2[V1, V2]

func (S2[V1, V2]) Unzip

func (s S2[V1, V2]) Unzip() ([]V1, []V2)

Unzip unpacks elements of tuple to slice.

type S3

type S3[V1, V2, V3 any] []T3[V1, V2, V3]

S3 is a slice of 3-ary tuple.

func Zip3

func Zip3[V1, V2, V3 any](s1 []V1, s2 []V2, s3 []V3) S3[V1, V2, V3]

func (S3[V1, V2, V3]) Unzip

func (s S3[V1, V2, V3]) Unzip() ([]V1, []V2, []V3)

Unzip unpacks elements of tuple to slice.

type S4

type S4[V1, V2, V3, V4 any] []T4[V1, V2, V3, V4]

S4 is a slice of 4-ary tuple.

func Zip4

func Zip4[V1, V2, V3, V4 any](s1 []V1, s2 []V2, s3 []V3, s4 []V4) S4[V1, V2, V3, V4]

func (S4[V1, V2, V3, V4]) Unzip

func (s S4[V1, V2, V3, V4]) Unzip() ([]V1, []V2, []V3, []V4)

Unzip unpacks elements of tuple to slice.

type S5

type S5[V1, V2, V3, V4, V5 any] []T5[V1, V2, V3, V4, V5]

S5 is a slice of 5-ary tuple.

func Zip5

func Zip5[V1, V2, V3, V4, V5 any](s1 []V1, s2 []V2, s3 []V3, s4 []V4, s5 []V5) S5[V1, V2, V3, V4, V5]

func (S5[V1, V2, V3, V4, V5]) Unzip

func (s S5[V1, V2, V3, V4, V5]) Unzip() ([]V1, []V2, []V3, []V4, []V5)

Unzip unpacks elements of tuple to slice.

type S6

type S6[V1, V2, V3, V4, V5, V6 any] []T6[V1, V2, V3, V4, V5, V6]

S6 is a slice of 6-ary tuple.

func Zip6

func Zip6[V1, V2, V3, V4, V5, V6 any](s1 []V1, s2 []V2, s3 []V3, s4 []V4, s5 []V5, s6 []V6) S6[V1, V2, V3, V4, V5, V6]

func (S6[V1, V2, V3, V4, V5, V6]) Unzip

func (s S6[V1, V2, V3, V4, V5, V6]) Unzip() ([]V1, []V2, []V3, []V4, []V5, []V6)

Unzip unpacks elements of tuple to slice.

type S7

type S7[V1, V2, V3, V4, V5, V6, V7 any] []T7[V1, V2, V3, V4, V5, V6, V7]

S7 is a slice of 7-ary tuple.

func Zip7

func Zip7[V1, V2, V3, V4, V5, V6, V7 any](s1 []V1, s2 []V2, s3 []V3, s4 []V4, s5 []V5, s6 []V6, s7 []V7) S7[V1, V2, V3, V4, V5, V6, V7]

func (S7[V1, V2, V3, V4, V5, V6, V7]) Unzip

func (s S7[V1, V2, V3, V4, V5, V6, V7]) Unzip() ([]V1, []V2, []V3, []V4, []V5, []V6, []V7)

Unzip unpacks elements of tuple to slice.

type S8

type S8[V1, V2, V3, V4, V5, V6, V7, V8 any] []T8[V1, V2, V3, V4, V5, V6, V7, V8]

S8 is a slice of 8-ary tuple.

func Zip8

func Zip8[V1, V2, V3, V4, V5, V6, V7, V8 any](s1 []V1, s2 []V2, s3 []V3, s4 []V4, s5 []V5, s6 []V6, s7 []V7, s8 []V8) S8[V1, V2, V3, V4, V5, V6, V7, V8]

func (S8[V1, V2, V3, V4, V5, V6, V7, V8]) Unzip

func (s S8[V1, V2, V3, V4, V5, V6, V7, V8]) Unzip() ([]V1, []V2, []V3, []V4, []V5, []V6, []V7, []V8)

Unzip unpacks elements of tuple to slice.

type S9

type S9[V1, V2, V3, V4, V5, V6, V7, V8, V9 any] []T9[V1, V2, V3, V4, V5, V6, V7, V8, V9]

S9 is a slice of 9-ary tuple.

func Zip9

func Zip9[V1, V2, V3, V4, V5, V6, V7, V8, V9 any](s1 []V1, s2 []V2, s3 []V3, s4 []V4, s5 []V5, s6 []V6, s7 []V7, s8 []V8, s9 []V9) S9[V1, V2, V3, V4, V5, V6, V7, V8, V9]

func (S9[V1, V2, V3, V4, V5, V6, V7, V8, V9]) Unzip

func (s S9[V1, V2, V3, V4, V5, V6, V7, V8, V9]) Unzip() ([]V1, []V2, []V3, []V4, []V5, []V6, []V7, []V8, []V9)

Unzip unpacks elements of tuple to slice.

type S10

type S10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10 any] []T10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10]

S10 is a slice of 10-ary tuple.

func Zip10

func Zip10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10 any](s1 []V1, s2 []V2, s3 []V3, s4 []V4, s5 []V5, s6 []V6, s7 []V7, s8 []V8, s9 []V9, s10 []V10) S10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10]

func (S10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10]) Unzip

func (s S10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10]) Unzip() ([]V1, []V2, []V3, []V4, []V5, []V6, []V7, []V8, []V9, []V10)

Unzip unpacks elements of tuple to slice.

type T2

type T2[V1, V2 any] struct {
	First  V1
	Second V2
}

T2 is a 2-ary tuple.

func Make2

func Make2[V1, V2 any](first V1, second V2) T2[V1, V2]

Make2 creates a tuple of 2 elements.

func (T2[V1, V2]) Values

func (t T2[V1, V2]) Values() (V1, V2)

Values returns all elements of tuple.

type T3

type T3[V1, V2, V3 any] struct {
	First  V1
	Second V2
	Third  V3
}

T3 is a 3-ary tuple.

func Make3

func Make3[V1, V2, V3 any](first V1, second V2, third V3) T3[V1, V2, V3]

Make3 creates a tuple of 3 elements.

func (T3[V1, V2, V3]) Values

func (t T3[V1, V2, V3]) Values() (V1, V2, V3)

Values returns all elements of tuple.

type T4

type T4[V1, V2, V3, V4 any] struct {
	First  V1
	Second V2
	Third  V3
	Fourth V4
}

T4 is a 4-ary tuple.

func Make4

func Make4[V1, V2, V3, V4 any](first V1, second V2, third V3, fourth V4) T4[V1, V2, V3, V4]

Make4 creates a tuple of 4 elements.

func (T4[V1, V2, V3, V4]) Values

func (t T4[V1, V2, V3, V4]) Values() (V1, V2, V3, V4)

Values returns all elements of tuple.

type T5

type T5[V1, V2, V3, V4, V5 any] struct {
	First  V1
	Second V2
	Third  V3
	Fourth V4
	Fifth  V5
}

T5 is a 5-ary tuple.

func Make5

func Make5[V1, V2, V3, V4, V5 any](first V1, second V2, third V3, fourth V4, fifth V5) T5[V1, V2, V3, V4, V5]

Make5 creates a tuple of 5 elements.

func (T5[V1, V2, V3, V4, V5]) Values

func (t T5[V1, V2, V3, V4, V5]) Values() (V1, V2, V3, V4, V5)

Values returns all elements of tuple.

type T6

type T6[V1, V2, V3, V4, V5, V6 any] struct {
	First  V1
	Second V2
	Third  V3
	Fourth V4
	Fifth  V5
	Sixth  V6
}

T6 is a 6-ary tuple.

func Make6

func Make6[V1, V2, V3, V4, V5, V6 any](first V1, second V2, third V3, fourth V4, fifth V5, sixth V6) T6[V1, V2, V3, V4, V5, V6]

Make6 creates a tuple of 6 elements.

func (T6[V1, V2, V3, V4, V5, V6]) Values

func (t T6[V1, V2, V3, V4, V5, V6]) Values() (V1, V2, V3, V4, V5, V6)

Values returns all elements of tuple.

type T7

type T7[V1, V2, V3, V4, V5, V6, V7 any] struct {
	First   V1
	Second  V2
	Third   V3
	Fourth  V4
	Fifth   V5
	Sixth   V6
	Seventh V7
}

T7 is a 7-ary tuple.

func Make7

func Make7[V1, V2, V3, V4, V5, V6, V7 any](first V1, second V2, third V3, fourth V4, fifth V5, sixth V6, seventh V7) T7[V1, V2, V3, V4, V5, V6, V7]

Make7 creates a tuple of 7 elements.

func (T7[V1, V2, V3, V4, V5, V6, V7]) Values

func (t T7[V1, V2, V3, V4, V5, V6, V7]) Values() (V1, V2, V3, V4, V5, V6, V7)

Values returns all elements of tuple.

type T8

type T8[V1, V2, V3, V4, V5, V6, V7, V8 any] struct {
	First   V1
	Second  V2
	Third   V3
	Fourth  V4
	Fifth   V5
	Sixth   V6
	Seventh V7
	Eighth  V8
}

T8 is a 8-ary tuple.

func Make8

func Make8[V1, V2, V3, V4, V5, V6, V7, V8 any](first V1, second V2, third V3, fourth V4, fifth V5, sixth V6, seventh V7, eighth V8) T8[V1, V2, V3, V4, V5, V6, V7, V8]

Make8 creates a tuple of 8 elements.

func (T8[V1, V2, V3, V4, V5, V6, V7, V8]) Values

func (t T8[V1, V2, V3, V4, V5, V6, V7, V8]) Values() (V1, V2, V3, V4, V5, V6, V7, V8)

Values returns all elements of tuple.

type T9

type T9[V1, V2, V3, V4, V5, V6, V7, V8, V9 any] struct {
	First   V1
	Second  V2
	Third   V3
	Fourth  V4
	Fifth   V5
	Sixth   V6
	Seventh V7
	Eighth  V8
	Ninth   V9
}

T9 is a 9-ary tuple.

func Make9

func Make9[V1, V2, V3, V4, V5, V6, V7, V8, V9 any](first V1, second V2, third V3, fourth V4, fifth V5, sixth V6, seventh V7, eighth V8, ninth V9) T9[V1, V2, V3, V4, V5, V6, V7, V8, V9]

Make9 creates a tuple of 9 elements.

func (T9[V1, V2, V3, V4, V5, V6, V7, V8, V9]) Values

func (t T9[V1, V2, V3, V4, V5, V6, V7, V8, V9]) Values() (V1, V2, V3, V4, V5, V6, V7, V8, V9)

Values returns all elements of tuple.

type T10

type T10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10 any] struct {
	First   V1
	Second  V2
	Third   V3
	Fourth  V4
	Fifth   V5
	Sixth   V6
	Seventh V7
	Eighth  V8
	Ninth   V9
	Tenth   V10
}

T10 is a 10-ary tuple.

func Make10

func Make10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10 any](first V1, second V2, third V3, fourth V4, fifth V5, sixth V6, seventh V7, eighth V8, ninth V9, tenth V10) T10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10]

Make10 creates a tuple of 10 elements.

func (T10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10]) Values

func (t T10[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10]) Values() (V1, V2, V3, V4, V5, V6, V7, V8, V9, V10)

Values returns all elements of tuple.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL