Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add[V ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~string | ~float32 | ~float64](a, b V) V
Add returns the sum of `a` and `b`.
Example ¶
package main
import (
"fmt"
"slices"
"github.com/BooleanCat/go-functional/v2/it"
"github.com/BooleanCat/go-functional/v2/it/op"
)
func main() {
fmt.Println(it.Fold(slices.Values([]int{1, 2, 3}), op.Add, 0))
}
Output: 6
Example (String) ¶
package main
import (
"fmt"
"slices"
"github.com/BooleanCat/go-functional/v2/it"
"github.com/BooleanCat/go-functional/v2/it/op"
)
func main() {
fmt.Println(it.Fold(slices.Values([]string{"a", "b", "c"}), op.Add, ""))
}
Output: abc
func Deref ¶ added in v2.5.0
func Deref[V any](v *V) V
Deref returns the value pointed to by the provided pointer.
Example ¶
package main
import (
"fmt"
"slices"
"github.com/BooleanCat/go-functional/v2/it"
"github.com/BooleanCat/go-functional/v2/it/op"
)
func main() {
intRef := func(a int) *int {
return &a
}
values := slices.Values([]*int{intRef(4), intRef(5), intRef(6)})
fmt.Println(slices.Collect(it.Map(values, op.Deref)))
}
Output: [4 5 6]
func Ref ¶ added in v2.5.0
func Ref[V any](v V) *V
Ref returns a reference to the provided value.
Example ¶
package main
import (
"fmt"
"slices"
"github.com/BooleanCat/go-functional/v2/it"
"github.com/BooleanCat/go-functional/v2/it/op"
)
func main() {
refs := slices.Collect(it.Map(slices.Values([]int{5, 6, 7}), op.Ref))
fmt.Println(*refs[0], *refs[1], *refs[2])
}
Output: 5 6 7
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.