Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func F ¶
Example (CustomTransform) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { // Custom transformation function numbers := []int{1, 2, 3, 4} squared := smap.F(numbers, func(x int) int { return x * x }) fmt.Printf("%v -> %v\n", numbers, squared) }
Output: [1 2 3 4] -> [1 4 9 16]
Example (StringTransform) ¶
package main import ( "fmt" "strings" "github.com/ggpls/smap" ) func main() { // Transform strings to uppercase words := []string{"hello", "world"} upper := smap.F(words, strings.ToUpper) fmt.Printf("%q -> %q\n", words, upper) }
Output: ["hello" "world"] -> ["HELLO" "WORLD"]
Example (TypeConversion) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { // Convert integers to their string representation numbers := []int{42, 100, 999} formatted := smap.F(numbers, func(n int) string { return fmt.Sprintf("Number: %d", n) }) fmt.Printf("%v -> %q\n", numbers, formatted) }
Output: [42 100 999] -> ["Number: 42" "Number: 100" "Number: 999"]
func N ¶
Example (Float32ToInt) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { floats32 := []float32{1.9, 2.2, 3.7, 4.1, 5.9} ints := smap.N[float32, int](floats32) fmt.Printf("%v -> %v\n", floats32, ints) }
Output: [1.9 2.2 3.7 4.1 5.9] -> [1 2 3 4 5]
Example (Float64ToFloat32) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { float64s := []float64{1.123456789, 2.123456789} float32s := smap.N[float64, float32](float64s) fmt.Printf("%.6f -> %.6f\n", float64s[0], float32s[0]) }
Output: 1.123457 -> 1.123457
Example (Int32ToInt64) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { int32s := []int32{100, 200, 300} int64s := smap.N[int32, int64](int32s) fmt.Printf("%v -> %v\n", int32s, int64s) }
Output: [100 200 300] -> [100 200 300]
Example (IntToFloat64) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { ints := []int{1, 2, 3, 4, 5} floats64 := smap.N[int, float64](ints) fmt.Printf("%v -> %v\n", ints, floats64) }
Output: [1 2 3 4 5] -> [1 2 3 4 5]
func S ¶
Example (BytesToString) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { byteSlices := [][]byte{ []byte("Golang"), []byte("Rules"), } strings := smap.S[[]byte, string](byteSlices) fmt.Printf("%q\n", strings) }
Output: ["Golang" "Rules"]
Example (StringToBytes) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { strings := []string{"Hello", "World"} bytes := smap.S[string, []byte](strings) // Print length of each byte slice to avoid platform-specific byte representations fmt.Printf("%q -> [%d, %d] (byte lengths)\n", strings, len(bytes[0]), len(bytes[1])) }
Output: ["Hello" "World"] -> [5, 5] (byte lengths)
Example (Utf8Handling) ¶
package main import ( "fmt" "github.com/ggpls/smap" ) func main() { // Test UTF-8 round trip conversion original := []string{"café", "über", "🚀"} bytes := smap.S[string, []byte](original) result := smap.S[[]byte, string](bytes) fmt.Printf("%q -> %q\n", original, result) }
Output: ["café" "über" "🚀"] -> ["café" "über" "🚀"]
Types ¶
type NType ¶
type NType interface { constraints.Integer | constraints.Float }
Click to show internal directories.
Click to hide internal directories.