two

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package two provides a 2-tuple type.

Example
package main

import (
	"fmt"

	"github.com/phelmkamp/valor/tuple/two"
)

func get() (string, int, bool) {
	return "a", 1, true
}

func main() {
	val := two.TupleValueOf(get())
	fmt.Println(val)
}
Output:

{{a 1} true}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func TupleResultOf

func TupleResultOf[T, T2 any](v T, v2 T2, err error) result.Result[Tuple[T, T2]]

TupleResultOf creates a result.Result of either (v, v2) or err. This aids interoperability with function return values.

func TupleUnzip added in v0.3.0

func TupleUnzip[T, T2, T3, T4 any](t four.Tuple[T, T2, T3, T4]) (Tuple[T, T3], Tuple[T2, T4])

TupleUnzip separates the values of t into two Tuples.

func TupleValueOf

func TupleValueOf[T, T2 any](v T, v2 T2, ok bool) optional.Value[Tuple[T, T2]]

TupleValueOf creates an optional.Value of (v, v2) if ok is true. This aids interoperability with return values that follow the "comma ok" idiom.

func TupleZip added in v0.3.0

func TupleZip[T, T2, T3, T4 any](t Tuple[T, T3], t2 Tuple[T2, T4]) four.Tuple[T, T2, T3, T4]

TupleZip combines the values of t and t2 into a four.Tuple.

Types

type Tuple

type Tuple[T, T2 any] struct {
	V  T
	V2 T2
}

Tuple contains two values.

func TupleMap added in v0.10.0

func TupleMap[T, T2, Tp, T2p any](t Tuple[T, T2], f func(T) Tp, f2 func(T2) T2p) (tp Tuple[Tp, T2p])

TupleMap returns a Tuple with each value replaced by the result of each function.

funcs.Ident can be used to leave the value unchanged.

func TupleOf

func TupleOf[T, T2 any](v T, v2 T2) Tuple[T, T2]

TupleOf creates a Tuple of (v, v2).

func (Tuple[T, T2]) Values added in v0.6.0

func (t Tuple[T, T2]) Values() (v T, v2 T2)

Values returns the contained values. This aids in assigning to variables or function arguments.

Jump to

Keyboard shortcuts

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