Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply[A, B any](ab func(A) B, a A) B
Example ¶
package main
import (
"fmt"
"github.com/calebcase/base/data/function"
)
func main() {
fmt.Println(function.Apply(
func(x int) int {
return x + 1
},
2,
))
}
Output: 3
func Compose ¶
func Compose[A, B, C any](bc func(B) C, ab func(A) B, a A) C
Example ¶
package main
import (
"fmt"
"github.com/calebcase/base/data/function"
)
func main() {
fmt.Println(function.Compose(
func(x int) string {
return fmt.Sprint(x)
},
func(y float32) int {
return int(y)
},
3.14,
))
}
Output: 3
func Const ¶
func Const[A, B any](a A, _ B) A
Example ¶
package main
import (
"fmt"
"github.com/calebcase/base/data/function"
)
func main() {
fmt.Println(function.Const(1, true))
}
Output: 1
func Flip ¶
func Flip[A, B, C any](abc func(A, B) C, b B, a A) C
Example ¶
package main
import (
"fmt"
"github.com/calebcase/base/data/function"
)
func main() {
fmt.Println(function.Flip(
func(a, b string) string {
return a + " " + b
},
"world",
"hello",
))
}
Output: hello world
func Id ¶
func Id[A any](a A) A
Example ¶
package main
import (
"fmt"
"github.com/calebcase/base/data/function"
)
func main() {
fmt.Println(function.Id(3))
fmt.Println(function.Id("hello"))
}
Output: 3 hello
func On ¶
func On[A, B, C any](b func(B, B) C, u func(A) B, x A, y A) C
Example ¶
package main
import (
"fmt"
"github.com/calebcase/base/data/function"
)
func main() {
v := function.On(
func(a, b string) string {
return a + b
},
func(x int) string {
return fmt.Sprint(x)
},
4,
2,
)
fmt.Printf("%v %T", v, v)
}
Output: 42 string
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.