Documentation
¶
Index ¶
- func Add[T constraints.Integer | constraints.Float | ~string](a, b T) T
- func BitwiseAnd[T constraints.Integer](a, b T) T
- func BitwiseOr[T constraints.Integer](a, b T) T
- func BitwiseXor[T constraints.Integer](a, b T) T
- func Multiply[T constraints.Integer | constraints.Float](a, b T) T
- func Passthrough[T any](t T) T
- func UnwrapOption[T any](o option.Option[T]) T
- func UnwrapResult[T any](r result.Result[T]) T
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶ added in v0.3.0
func Add[T constraints.Integer | constraints.Float | ~string](a, b T) T
Add performs the `+` operation for the two inputs, returning the result.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
)
func main() {
total := iter.Fold[int](iter.Lift([]int{1, 2, 3}), 0, ops.Add[int])
fmt.Println(total)
}
Output: 6
func BitwiseAnd ¶ added in v0.5.0
func BitwiseAnd[T constraints.Integer](a, b T) T
BitwiseAnd performs the `&` operation for the two inputs, returning the result.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
)
func main() {
overlap := iter.Fold[int](iter.Lift([]int{5, 7, 13}), -1, ops.BitwiseAnd[int])
fmt.Println(overlap)
}
Output: 5
func BitwiseOr ¶ added in v0.5.0
func BitwiseOr[T constraints.Integer](a, b T) T
BitwiseOr performs the `|` operation for the two inputs, returning the result.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
)
func main() {
union := iter.Fold[int](iter.Lift([]int{1, 2, 6}), 0, ops.BitwiseOr[int])
fmt.Println(union)
}
Output: 7
func BitwiseXor ¶ added in v0.5.0
func BitwiseXor[T constraints.Integer](a, b T) T
BitwiseXor performs the `^` operation for the two inputs, returning the result.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
)
func main() {
result := iter.Fold[int](iter.Lift([]int{1, 2, 6}), 0, ops.BitwiseXor[int])
fmt.Println(result)
}
Output: 5
func Multiply ¶ added in v0.5.0
func Multiply[T constraints.Integer | constraints.Float](a, b T) T
Multiply performs the `*` operation for the two inputs, returning the result.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
)
func main() {
product := iter.Fold[int](iter.Lift([]int{3, 4, 5}), 2, ops.Multiply[int])
fmt.Println(product)
}
Output: 120
func Passthrough ¶ added in v0.5.0
func Passthrough[T any](t T) T
Passthrough may be used an an operation for iter.Map. It returns the provided value without modification.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
)
func main() {
numbers := iter.Map[int](iter.Lift([]int{1, 2, 3}), ops.Passthrough[int])
fmt.Println(iter.Collect[int](numbers))
}
Output: [1 2 3]
func UnwrapOption ¶
UnwrapOption may be used as an operation for iter.Map in order to unwrap all options in an iterator.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
"github.com/BooleanCat/go-functional/option"
)
func main() {
options := iter.Lift([]option.Option[int]{
option.Some(4),
option.Some(6),
option.Some(-1),
})
numbers := iter.Map[option.Option[int]](options, ops.UnwrapOption[int])
fmt.Println(iter.Collect[int](numbers))
}
Output: [4 6 -1]
func UnwrapResult ¶
UnwrapResult may be used as an operation for iter.Map in order to unwrap all results in an iterator.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/iter"
"github.com/BooleanCat/go-functional/iter/ops"
"github.com/BooleanCat/go-functional/result"
)
func main() {
results := iter.Lift([]result.Result[int]{
result.Ok(1),
result.Ok(3),
result.Ok(-6),
})
numbers := iter.Map[result.Result[int]](results, ops.UnwrapResult[int])
fmt.Println(iter.Collect[int](numbers))
}
Output: [1 3 -6]
Types ¶
This section is empty.