either

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Copyright 2022 IBM Corp.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2022 IBM Corp.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2022 IBM Corp.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alt

func Alt[E, A any](that func() Either[E, A]) func(Either[E, A]) Either[E, A]

func AltW

func AltW[E, E1, A any](that func() Either[E1, A]) func(Either[E, A]) Either[E1, A]

func Ap

func Ap[E, A, B any](fa Either[E, A]) func(fab Either[E, func(a A) B]) Either[E, B]

func Chain

func Chain[E, A, B any](f func(a A) Either[E, B]) func(Either[E, A]) Either[E, B]

func ChainOptionK

func ChainOptionK[E, A, B any](onNone func() E) func(func(A) O.Option[B]) func(Either[E, A]) Either[E, B]

func Eitherize0

func Eitherize0[R any](f func() (R, error)) func() Either[error, R]

func Eitherize1

func Eitherize1[T1, R any](f func(t1 T1) (R, error)) func(t1 T1) Either[error, R]

func Eitherize2

func Eitherize2[T1, T2, R any](f func(t1 T1, t2 T2) (R, error)) func(t1 T1, t2 T2) Either[error, R]

func Fold

func Fold[E, A, B any](onLeft func(e E) B, onRight func(a A) B) func(ma Either[E, A]) B

func FromNillable

func FromNillable[E, A any](e E) func(*A) Either[E, *A]

func FromOption

func FromOption[E, A any](onNone func() E) func(O.Option[A]) Either[E, A]

func FromPredicate

func FromPredicate[E, A any](pred func(a A) bool, onFalse func(a A) E) func(value A) Either[E, A]

func GetOrElse

func GetOrElse[E, A any](onLeft func(E) A) func(Either[E, A]) A

func IsLeft

func IsLeft[E, A any](val Either[E, A]) bool

func IsRight

func IsRight[E, A any](val Either[E, A]) bool

func Map

func Map[E, A, B any](f func(a A) B) func(fa Either[E, A]) Either[E, B]

func MapLeft

func MapLeft[E, A, B any](f func(E) B) func(fa Either[E, A]) Either[B, A]

func MapTo

func MapTo[E, A, B any](b B) func(Either[E, A]) Either[E, B]

func Sequence2

func Sequence2[E, T1, T2, R any](f func(T1, T2) Either[E, R]) func(Either[E, T1], Either[E, T2]) Either[E, R]

func Sequence3 added in v0.1.6

func Sequence3[E, T1, T2, T3, R any](f func(T1, T2, T3) Either[E, R]) func(Either[E, T1], Either[E, T2], Either[E, T3]) Either[E, R]

func SequenceArray

func SequenceArray[E, A any]() func([]Either[E, A]) Either[E, []A]

func ToError

func ToError[A any](e Either[error, A]) error

func TraverseArray

func TraverseArray[E, A, B any](f func(A) Either[E, B]) func([]A) Either[E, []B]

func WithResource

func WithResource[E, R, A any](onCreate func() Either[E, R], onRelease func(R) Either[E, any]) func(func(R) Either[E, A]) Either[E, A]

WithResource constructs a function that creates a resource, then operates on it and then releases the resource

Types

type Either

type Either[E, A any] interface {
	IsLeft() bool
	IsRight() bool
}

func Flatten

func Flatten[E, A any](mma Either[E, Either[E, A]]) Either[E, A]

func Left

func Left[E, A any](value E) Either[E, A]

func MonadAp

func MonadAp[E, A, B any](fab Either[E, func(a A) B], fa Either[E, A]) Either[E, B]

func MonadChain

func MonadChain[E, A, B any](fa Either[E, A], f func(a A) Either[E, B]) Either[E, B]

func MonadChainOptionK

func MonadChainOptionK[E, A, B any](onNone func() E, ma Either[E, A], f func(A) O.Option[B]) Either[E, B]

func MonadMap

func MonadMap[E, A, B any](fa Either[E, A], f func(a A) B) Either[E, B]

func MonadMapLeft

func MonadMapLeft[E, A, B any](fa Either[E, A], f func(E) B) Either[B, A]

func MonadMapTo

func MonadMapTo[E, A, B any](fa Either[E, A], b B) Either[E, B]

func MonadSequence2

func MonadSequence2[E, T1, T2, R any](e1 Either[E, T1], e2 Either[E, T2], f func(T1, T2) Either[E, R]) Either[E, R]

func MonadSequence3 added in v0.1.6

func MonadSequence3[E, T1, T2, T3, R any](e1 Either[E, T1], e2 Either[E, T2], e3 Either[E, T3], f func(T1, T2, T3) Either[E, R]) Either[E, R]

func Of

func Of[E, A any](value A) Either[E, A]
func Right[E, A any](value A) Either[E, A]

func TryCatch

func TryCatch[E, A any](f func() (A, error), onThrow func(error) E) Either[E, A]

func TryCatchError

func TryCatchError[A any](f func() (A, error)) Either[error, A]

Jump to

Keyboard shortcuts

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