ops

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

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 UnwrapOption

func UnwrapOption[T any](o option.Option[T]) T

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

func UnwrapResult[T any](r result.Result[T]) T

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL