Documentation ¶
Index ¶
- func All[T comparable](a []T, value T) bool
- func AllBy[T any](a []T, f func(int, T) bool) bool
- func Any[T comparable](a []T, value T) bool
- func AnyBy[T any](a []T, f func(index int, value T) bool) bool
- func Chain[S ~[]T, T any](a ...S) []T
- func Chunk[S ~[]T, T any](a S, size int) []S
- func Compress[S ~[]T, T any](a S, selectors []bool) S
- func Count[T comparable](a []T, value T) int
- func CountBy[T any](a []T, counter func(int, T) bool) int
- func DropWhile[S ~[]T, T any](a S, predicate func(int, T) bool) S
- func Filter[S ~[]T, T any](a S, filter func(int, T) bool) S
- func FilterFalse[S ~[]T, T any](a S, filter func(int, T) bool) S
- func GroupBy[S ~[]T, T any, K comparable](a S, f func(int, T) K) map[K]S
- func If[T any](cond bool, trueValue, falseValue T) T
- func Map[S1 ~[]T1, S2 []T2, T1, T2 any](a S1, mapper func(int, T1) T2) S2
- func Max[S ~[]T, T cmp.Ordered](a S) optional.Optional[T]
- func Min[S ~[]T, T cmp.Ordered](a S) optional.Optional[T]
- func Must(err error)
- func Must0(err error)
- func Must1[T1 any](v1 T1, err error) T1
- func Must2[T1, T2 any](v1 T1, v2 T2, err error) (T1, T2)
- func Must3[T1, T2, T3 any](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)
- func Must4[T1, T2, T3, T4 any](v1 T1, v2 T2, v3 T3, v4 T4, err error) (T1, T2, T3, T4)
- func Must5[T1, T2, T3, T4, T5 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, err error) (T1, T2, T3, T4, T5)
- func Must6[T1, T2, T3, T4, T5, T6 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, err error) (T1, T2, T3, T4, T5, T6)
- func Must7[T1, T2, T3, T4, T5, T6, T7 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, err error) (T1, T2, T3, T4, T5, T6, T7)
- func Must8[T1, T2, T3, T4, T5, T6, T7, T8 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, err error) (T1, T2, T3, T4, T5, T6, T7, T8)
- func Negate[F ~func(T) bool, T any](f F) F
- func Negate2[F ~func(T, U) bool, T, U any](f F) F
- func Pairwise[S ~[]T, T any](a S) []tuple.Tuple2[T, T]
- func Ptr[T any](v T) *T
- func RepeatN[T any](v T, n int) []T
- func Sample[S ~[]T, T any](a S) optional.Optional[T]
- func SampleN[S ~[]T, T any](a S, n int) S
- func Shuffle[S ~[]T, T any](a S) S
- func Slice[S ~[]T, T any](s S, start, stop, step int) S
- func TakeWhile[S ~[]T, T any](a S, f func(int, T) bool) S
- func Unzip10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](s []tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10)
- func Unzip11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any](s []tuple.Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11)
- func Unzip12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any](s []tuple.Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12)
- func Unzip13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any](s []tuple.Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any](s []tuple.Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any](...) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any](...) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, ...)
- func Unzip2[T1, T2 any](s []tuple.Tuple2[T1, T2]) ([]T1, []T2)
- func Unzip3[T1, T2, T3 any](s []tuple.Tuple3[T1, T2, T3]) ([]T1, []T2, []T3)
- func Unzip4[T1, T2, T3, T4 any](s []tuple.Tuple4[T1, T2, T3, T4]) ([]T1, []T2, []T3, []T4)
- func Unzip5[T1, T2, T3, T4, T5 any](s []tuple.Tuple5[T1, T2, T3, T4, T5]) ([]T1, []T2, []T3, []T4, []T5)
- func Unzip6[T1, T2, T3, T4, T5, T6 any](s []tuple.Tuple6[T1, T2, T3, T4, T5, T6]) ([]T1, []T2, []T3, []T4, []T5, []T6)
- func Unzip7[T1, T2, T3, T4, T5, T6, T7 any](s []tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7)
- func Unzip8[T1, T2, T3, T4, T5, T6, T7, T8 any](s []tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8)
- func Unzip9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](s []tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9)
- func Zero[T any]() T
- func Zip10[S []tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], S1 ~[]T1, S2 ~[]T2, ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10) S
- func Zip11[S []tuple.Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11], S1 ~[]T1, ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, ...) S
- func Zip12[S []tuple.Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12], S1 ~[]T1, ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, ...) S
- func Zip13[S []tuple.Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13], ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, ...) S
- func Zip14[S []tuple.Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14], ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, ...) S
- func Zip15[...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, ...) S
- func Zip16[...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, ...) S
- func Zip2[S []tuple.Tuple2[T1, T2], S1 ~[]T1, S2 ~[]T2, T1, T2 any](s1 S1, s2 S2) S
- func Zip3[S []tuple.Tuple3[T1, T2, T3], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, T1, T2, T3 any](s1 S1, s2 S2, s3 S3) S
- func Zip4[S []tuple.Tuple4[T1, T2, T3, T4], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, ...](s1 S1, s2 S2, s3 S3, s4 S4) S
- func Zip5[S []tuple.Tuple5[T1, T2, T3, T4, T5], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5) S
- func Zip6[S []tuple.Tuple6[T1, T2, T3, T4, T5, T6], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6) S
- func Zip7[S []tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7) S
- func Zip8[S []tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8) S
- func Zip9[S []tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], S1 ~[]T1, S2 ~[]T2, ...](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9) S
- type Addable
- type SwitchCase
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
func All[T comparable](a []T, value T) bool
All returns whether all elements of a are value.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { fmt.Println(hi.All([]int{1, 2, 3, 4, 5}, 5)) fmt.Println(hi.All([]int{5, 5, 5, 5, 5}, 5)) }
Output: false true
func AllBy ¶
AllBy returns whether f returns true for all elements in a.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { fmt.Println(hi.AllBy([]int{1, 2, 3, 4, 5}, func(_, v int) bool { return v > 3 })) fmt.Println(hi.AllBy([]int{4, 5, 6, 7, 8}, func(_, v int) bool { return v > 3 })) }
Output: false true
func Any ¶
func Any[T comparable](a []T, value T) bool
Any returns whether a has value at least one.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} fmt.Println(hi.Any(input, 5)) fmt.Println(hi.Any(input, 6)) }
Output: true false
func AnyBy ¶
AnyBy returns whether a has an element for that f returns true.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} fmt.Println(hi.AnyBy(input, func(_, v int) bool { return v > 3 })) fmt.Println(hi.AnyBy(input, func(_, v int) bool { return v > 10 })) }
Output: true false
func Chain ¶
func Chain[S ~[]T, T any](a ...S) []T
Chain returns a slice of all elements from all slices.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input1 := []int{1, 2, 3} input2 := []int{4, 5, 6} output := hi.Chain(input1, input2) for _, v := range output { fmt.Println(v) } }
Output: 1 2 3 4 5 6
func Chunk ¶
Chunk creates a slice of elements split into groups the length of size.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} output := hi.Chunk(input, 2) for _, v := range output { fmt.Println(v) } }
Output: [1 2] [3 4] [5]
func Compress ¶
Compress makes a slice of the elements in a for which the corresponding element in selectors is true.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} selectors := []bool{true, false, true, false, true} output := hi.Compress(input, selectors) for _, v := range output { fmt.Println(v) } }
Output: 1 3 5
func Count ¶
func Count[T comparable](a []T, value T) int
Count counts the number of elements in the collection that compare equal to value.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} fmt.Println(hi.Count(input, 3)) }
Output: 1
func CountBy ¶
CountBy counts the number of elements that counter returns true.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} fmt.Println(hi.CountBy(input, func(_, v int) bool { return v%2 == 0 })) }
Output: 2
func DropWhile ¶
DropWhile returns a slice of the remaining elements after dropping the longest prefix of elements that satisfy predicate.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 4, 6, 4, 1} output := hi.DropWhile(input, func(_, v int) bool { return v < 5 }) for _, v := range output { fmt.Println(v) } }
Output: 6 4 1
func Filter ¶
Filter iterates over elements of collection, returning a slice of all elements predicate returns true for.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} output := hi.Filter(input, func(_, v int) bool { return v%2 == 0 }) for _, v := range output { fmt.Println(v) } }
Output: 2 4
func FilterFalse ¶
FilterFalse iterates over elements of collection, returning a slice of all elements predicate returns false for.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} output := hi.FilterFalse(input, func(_, v int) bool { return v%2 == 0 }) for _, v := range output { fmt.Println(v) } }
Output: 1 3 5
func GroupBy ¶
func GroupBy[S ~[]T, T any, K comparable](a S, f func(int, T) K) map[K]S
GroupBy returns a map of slices, where each slice contains elements of a grouped by the result of f.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} output := hi.GroupBy(input, func(_, v int) int { return v % 2 }) for k, v := range output { fmt.Println(k, v) } }
Output: 0 [2 4] 1 [1 3 5]
func If ¶
If is a 1 line if/else expression.
Example (Even) ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { v := 124 fmt.Println(hi.If(v%2 == 0, "even", "odd")) }
Output: even
Example (Odd) ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { v := 125 fmt.Println(hi.If(v%2 == 0, "even", "odd")) }
Output: odd
func Map ¶
Map calls mapper on each element of a and returns the result of its result in a slice.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} output := hi.Map(input, func(_, v int) string { return fmt.Sprintf("(%d)", v) }) for _, v := range output { fmt.Println(v) } }
Output: (1) (2) (3) (4) (5)
func Max ¶
Max returns the maximal value in a.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { max := hi.Max([]int{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}) fmt.Println(max.Get()) }
Output: 9
func Min ¶
Min returns the minimal value in a.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { min := hi.Min([]int{3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}) fmt.Println(min.Get()) }
Output: 1
func Must5 ¶
func Must5[T1, T2, T3, T4, T5 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, err error) (T1, T2, T3, T4, T5)
Must5 returns (v1, v2, v3, v4, v5) if err is nil, otherwise it panics.
func Must6 ¶
func Must6[T1, T2, T3, T4, T5, T6 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, err error) (T1, T2, T3, T4, T5, T6)
Must6 returns (v1, v2, v3, v4, v5, v6) if err is nil, otherwise it panics.
func Must7 ¶
func Must7[T1, T2, T3, T4, T5, T6, T7 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, err error) (T1, T2, T3, T4, T5, T6, T7)
Must7 returns (v1, v2, v3, v4, v5, v6, v7) if err is nil, otherwise it panics.
func Must8 ¶
func Must8[T1, T2, T3, T4, T5, T6, T7, T8 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, err error) (T1, T2, T3, T4, T5, T6, T7, T8)
Must8 returns (v1, v2, v3, v4, v5, v6, v7, v8) if err is nil, otherwise it panics.
func Negate ¶
Negate returns a function that negates the result of f.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { f := func(v int) bool { return v > 3 } g := hi.Negate(f) for i := 0; i < 5; i++ { fmt.Printf("%d: %t, %t\n", i, f(i), g(i)) } }
Output: 0: false, true 1: false, true 2: false, true 3: false, true 4: true, false
func Negate2 ¶
Negate2 returns a function that negates the result of f.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { f := func(a, b int) bool { return a > b } g := hi.Negate2(f) for i := 0; i < 5; i++ { fmt.Printf("%d: %t, %t\n", i, f(i, 3), g(i, 3)) } }
Output: 0: false, true 1: false, true 2: false, true 3: false, true 4: true, false
func Pairwise ¶
Pairwise makes a slice of all adjacent pairs of elements.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} output := hi.Pairwise(input) for _, v := range output { fmt.Println(v) } }
Output: (1, 2) (2, 3) (3, 4) (4, 5)
func Ptr ¶
func Ptr[T any](v T) *T
Ptr returns a pointer to v.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { p := hi.Ptr("hello") fmt.Println(*p) }
Output: hello
func RepeatN ¶
RepeatN returns a slice consisting of n copies of v.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { output := hi.RepeatN("hello", 3) for _, v := range output { fmt.Println(v) } }
Output: hello hello hello
func Shuffle ¶ added in v0.1.1
func Shuffle[S ~[]T, T any](a S) S
Shuffle returns a shuffled copy of a.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} output := hi.Shuffle(input) for _, v := range output { fmt.Println(v) } }
Output: 1 2 3 4 5
func Slice ¶
Slice returns a Python-like slice of s. Unlike Go's builtin slice, Slice can handle negative indices and step, and always returns a new slice. Negative indices count from the end of the slice (-1 means the last element).
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 2, 3, 4, 5} output := hi.Slice(input, 1, 3, 1) fmt.Println(output) }
Output: [2 3]
func TakeWhile ¶
TakeWhile returns a slice of the longest prefix of elements that satisfy predicate f.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { input := []int{1, 4, 6, 4, 1} output := hi.TakeWhile(input, func(_, v int) bool { return v < 5 }) for _, v := range output { fmt.Println(v) } }
Output: 1 4
func Unzip10 ¶
func Unzip10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](s []tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10)
Unzip10 converts a slice of 10-tuple to slices of each elements.
func Unzip11 ¶
func Unzip11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any](s []tuple.Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11)
Unzip11 converts a slice of 11-tuple to slices of each elements.
func Unzip12 ¶
func Unzip12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any](s []tuple.Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12)
Unzip12 converts a slice of 12-tuple to slices of each elements.
func Unzip13 ¶
func Unzip13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any](s []tuple.Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13)
Unzip13 converts a slice of 13-tuple to slices of each elements.
func Unzip14 ¶
func Unzip14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any](s []tuple.Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13, []T14)
Unzip14 converts a slice of 14-tuple to slices of each elements.
func Unzip15 ¶
func Unzip15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any](s []tuple.Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13, []T14, []T15)
Unzip15 converts a slice of 15-tuple to slices of each elements.
func Unzip16 ¶
func Unzip16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any](s []tuple.Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9, []T10, []T11, []T12, []T13, []T14, []T15, []T16)
Unzip16 converts a slice of 16-tuple to slices of each elements.
func Unzip2 ¶
Unzip2 converts a slice of 2-tuple to slices of each elements.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" "github.com/shogo82148/hi/tuple" ) func main() { slice := []tuple.Tuple2[int, string]{ tuple.New2(1, "one"), tuple.New2(2, "two"), tuple.New2(3, "three"), tuple.New2(4, "four"), tuple.New2(5, "five"), } s1, s2 := hi.Unzip2(slice) for _, v := range s1 { fmt.Println(v) } for _, v := range s2 { fmt.Println(v) } }
Output: 1 2 3 4 5 one two three four five
func Unzip5 ¶
func Unzip5[T1, T2, T3, T4, T5 any](s []tuple.Tuple5[T1, T2, T3, T4, T5]) ([]T1, []T2, []T3, []T4, []T5)
Unzip5 converts a slice of 5-tuple to slices of each elements.
func Unzip6 ¶
func Unzip6[T1, T2, T3, T4, T5, T6 any](s []tuple.Tuple6[T1, T2, T3, T4, T5, T6]) ([]T1, []T2, []T3, []T4, []T5, []T6)
Unzip6 converts a slice of 6-tuple to slices of each elements.
func Unzip7 ¶
func Unzip7[T1, T2, T3, T4, T5, T6, T7 any](s []tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7)
Unzip7 converts a slice of 7-tuple to slices of each elements.
func Unzip8 ¶
func Unzip8[T1, T2, T3, T4, T5, T6, T7, T8 any](s []tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8)
Unzip8 converts a slice of 8-tuple to slices of each elements.
func Unzip9 ¶
func Unzip9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](s []tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) ([]T1, []T2, []T3, []T4, []T5, []T6, []T7, []T8, []T9)
Unzip9 converts a slice of 9-tuple to slices of each elements.
func Zip10 ¶
func Zip10[S []tuple.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, S9 ~[]T9, S10 ~[]T10, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10) S
Zip10 returns a slice of 10-tuples. The returned slice have the length of the shortest slice.
func Zip11 ¶
func Zip11[S []tuple.Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, S9 ~[]T9, S10 ~[]T10, S11 ~[]T11, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, s11 S11) S
Zip11 returns a slice of 11-tuples. The returned slice have the length of the shortest slice.
func Zip12 ¶
func Zip12[S []tuple.Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, S9 ~[]T9, S10 ~[]T10, S11 ~[]T11, S12 ~[]T12, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, s11 S11, s12 S12) S
Zip12 returns a slice of 12-tuples. The returned slice have the length of the shortest slice.
func Zip13 ¶
func Zip13[S []tuple.Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, S9 ~[]T9, S10 ~[]T10, S11 ~[]T11, S12 ~[]T12, S13 ~[]T13, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, s11 S11, s12 S12, s13 S13) S
Zip13 returns a slice of 13-tuples. The returned slice have the length of the shortest slice.
func Zip14 ¶
func Zip14[S []tuple.Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, S9 ~[]T9, S10 ~[]T10, S11 ~[]T11, S12 ~[]T12, S13 ~[]T13, S14 ~[]T14, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, s11 S11, s12 S12, s13 S13, s14 S14) S
Zip14 returns a slice of 14-tuples. The returned slice have the length of the shortest slice.
func Zip15 ¶
func Zip15[S []tuple.Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, S9 ~[]T9, S10 ~[]T10, S11 ~[]T11, S12 ~[]T12, S13 ~[]T13, S14 ~[]T14, S15 ~[]T15, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, s11 S11, s12 S12, s13 S13, s14 S14, s15 S15) S
Zip15 returns a slice of 15-tuples. The returned slice have the length of the shortest slice.
func Zip16 ¶
func Zip16[S []tuple.Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, S9 ~[]T9, S10 ~[]T10, S11 ~[]T11, S12 ~[]T12, S13 ~[]T13, S14 ~[]T14, S15 ~[]T15, S16 ~[]T16, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9, s10 S10, s11 S11, s12 S12, s13 S13, s14 S14, s15 S15, s16 S16) S
Zip16 returns a slice of 16-tuples. The returned slice have the length of the shortest slice.
func Zip2 ¶
Zip2 returns a slice of 2-tuples. The returned slice have the length of the shortest slice.
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { ints := []int{1, 2, 3, 4, 5} strings := []string{"one", "two", "three", "four", "five"} slice := hi.Zip2(ints, strings) for _, v := range slice { fmt.Println(v) } }
Output: (1, one) (2, two) (3, three) (4, four) (5, five)
func Zip3 ¶
func Zip3[S []tuple.Tuple3[T1, T2, T3], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, T1, T2, T3 any](s1 S1, s2 S2, s3 S3) S
Zip3 returns a slice of 3-tuples. The returned slice have the length of the shortest slice.
func Zip4 ¶
func Zip4[S []tuple.Tuple4[T1, T2, T3, T4], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, T1, T2, T3, T4 any](s1 S1, s2 S2, s3 S3, s4 S4) S
Zip4 returns a slice of 4-tuples. The returned slice have the length of the shortest slice.
func Zip5 ¶
func Zip5[S []tuple.Tuple5[T1, T2, T3, T4, T5], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, T1, T2, T3, T4, T5 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5) S
Zip5 returns a slice of 5-tuples. The returned slice have the length of the shortest slice.
func Zip6 ¶
func Zip6[S []tuple.Tuple6[T1, T2, T3, T4, T5, T6], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, T1, T2, T3, T4, T5, T6 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6) S
Zip6 returns a slice of 6-tuples. The returned slice have the length of the shortest slice.
func Zip7 ¶
func Zip7[S []tuple.Tuple7[T1, T2, T3, T4, T5, T6, T7], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, T1, T2, T3, T4, T5, T6, T7 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7) S
Zip7 returns a slice of 7-tuples. The returned slice have the length of the shortest slice.
func Zip8 ¶
func Zip8[S []tuple.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, T1, T2, T3, T4, T5, T6, T7, T8 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8) S
Zip8 returns a slice of 8-tuples. The returned slice have the length of the shortest slice.
func Zip9 ¶
func Zip9[S []tuple.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], S1 ~[]T1, S2 ~[]T2, S3 ~[]T3, S4 ~[]T4, S5 ~[]T5, S6 ~[]T6, S7 ~[]T7, S8 ~[]T8, S9 ~[]T9, T1, T2, T3, T4, T5, T6, T7, T8, T9 any](s1 S1, s2 S2, s3 S3, s4 S4, s5 S5, s6 S6, s7 S7, s8 S8, s9 S9) S
Zip9 returns a slice of 9-tuples. The returned slice have the length of the shortest slice.
Types ¶
type Addable ¶
type Addable interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~complex64 | ~complex128 }
Addable is a type that can be added and subtracted.
type SwitchCase ¶
type SwitchCase[T any, P comparable] struct { // contains filtered or unexported fields }
func Switch ¶
func Switch[T any, P comparable](predicate P) SwitchCase[T, P]
Example ¶
package main import ( "fmt" "github.com/shogo82148/hi" ) func main() { v := 2 fmt.Println(hi.Switch[string](v). Case(1, "one"). Case(2, "two"). Case(3, "three"). Default("four or greater")) }
Output: two
func (SwitchCase[T, P]) Case ¶
func (s SwitchCase[T, P]) Case(val P, result T) SwitchCase[T, P]
func (SwitchCase[T, P]) Default ¶
func (s SwitchCase[T, P]) Default(result T) T
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package it provides utilities for iterators.
|
Package it provides utilities for iterators. |
Package list implements a generic doubly linked list.
|
Package list implements a generic doubly linked list. |
The package sync provides same features as the standard sync package, but with generics.
|
The package sync provides same features as the standard sync package, but with generics. |
Code generated by generate-tuples.pl; DO NOT EDIT.
|
Code generated by generate-tuples.pl; DO NOT EDIT. |