oprs

package module
v0.0.0-...-eb2585e Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: BSD-3-Clause Imports: 8 Imported by: 4

README

operators

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPrinter = os.Stdout

Functions

func After

func After[I, O any](fn func(I) O, op func()) func(I) O

func All

func All[T any](preds ...func(T) bool) func(T) bool

All AND-concatenates a sequence of boolean operators with of a shared type If no argument is given, the returned predicate will check if its argument's pointer is nil

func And

func And[L, R any](one func(L) bool, two func(R) bool) func(L, R) bool

And returns the && gate for non-boolean types

func Any

func Any[T any](preds ...func(T) bool) func(T) bool

Any OR-concatenates a sequence of boolean operators with of a shared type If no argument is given, the returned predicate will check if its argument's pointer is nil

func AreAll

func AreAll[I any](f func(I) bool) func(...I) bool

func Assert

func Assert[T any](arg any) *T

Assert uses type assertion to convert a given interface{} into a literal of the given T

func Before

func Before[I, O any](fn func(I) O, op func()) func(I) O

func Bind

func Bind[L, R, T any](f func(L, R) T, val R) func(L) T

Bind turns a diadic function of upto two types into a monadic one It is like Method, except it targets the right operand

func BindEach

func BindEach[L, R, T any](fn func(L, R) T, vals ...R) []func(L) T

BindEach creates a collection of unary operators from a binary operator and a collection of operands

func BindOp

func BindOp[T, U, V, L, R any](f func(T, func(L, R) U) V, op func(L, R) U) func(T) V

BindOp turns a diadic function of some type and binary operator into a monadic one It is like MethodOp, except it targets the right operand

func BindVar

func BindVar[L, R, T any](f func(L, R) T, v func() R) func(L) T

BindVar turns a diadic function of upto two types into a monadic one It is like MethodVar, except it targets the right operand

func Both

func Both[T any](one, two func(T) bool) func(T) bool

Both offers the AND gate

func Capy

func Capy[T any](dst *[]T, src []T) int

Capy copies elements from a source slice into a destination slice with respect to its capacity. The source and destination may overlap. It is a no-op if the destination's length equals its capacity. Returns the number of elements copied, which will be:

		0				if src is empty or dst is full
cap(dst) - len(dst); 	unless
cap(dst) - len(src)		is smaller but non-negative

func Cast

func Cast[O, I rules.Real](arg I) O

Cast allows you to convert between real number types

func Chars

func Chars[char byte | rune](w string) (out []char)

Chars returns the byes or runes associated with a string

func Clone

func Clone[T any](arg *T) *T

Clone duplicates an object in memory

func CurryL

func CurryL[L, R, T any](f func(L, R) T) func(L) func(R) T

func CurryLV

func CurryLV[L, R, T any](f func(L, ...R) T) func(L) func(...R) T

func CurryR

func CurryR[L, R, T any](f func(L, R) T) func(R) func(L) T

func CurryRV

func CurryRV[L, R, T any](f func(L, ...R) T) func(...R) func(L) T

func Denull

func Denull[T comparable](ptr *T, val T)

Denull sets the value of a pointer if it's current value is zero-like See ToBool

func DenullLener

func DenullLener[Seq rules.Lener[K, V], K comparable, V any](ptr *Seq, val Seq)

DenullLener sets the value of a pointer if it's current value is zero-like See ToBoolLener

func DropLeft

func DropLeft[I, L, R any](fn func(I) (L, R)) func(I) R

DropLeft strips a function of its left-most return value

func DropRight

func DropRight[I, L, R any](fn func(I) (L, R)) func(I) L

DropRight strips a function of its right-most return value

func Either

func Either[T any](one, two func(T) bool) func(T) bool

Either offers the OR gate

func Eq

func Eq[T comparable](a, b T) bool

Eq compares two values for equality

func Flip

func Flip[L, R, T any](op func(L, R) T) func(R, L) T

Flip changes the order of arguments for a binary operator

func Fprinter

func Fprinter(w io.Writer) func(...any) (int, error)

Fprinter returns a closure that prints to the given writer defaults to DefaultPrinter if writer is nil

func Fprinterf

func Fprinterf(w io.Writer, format string) func(...any) (int, error)

Fprinterf returns a closure that prints a format string to the given writer defaults to DefaultPrinter if writer is nil

func Fprinterln

func Fprinterln(w io.Writer) func(...any) (int, error)

Fprinterln returns a closure that prints a line to the given writer defaults to DefaultPrinter if writer is nil

func Ge

func Ge[T rules.Ordered](a, b T) bool

Ge calls ">="

func Gt

func Gt[T rules.Ordered](a, b T) bool

Gt calls ">"

func Imag

func Imag[N rules.Real, C rules.Complex](arg C) N

Imag extracts the imaginary part of a complex number

func Integrate

func Integrate[I, O any](f func(I) O) func([]I) []O

Integrate transforms a function between two types into one between arrays of their instances

func Is

func Is[T comparable](val T) func(T) bool

Is creates an equivalence predicate for a value

func IsEven

func IsEven[T rules.Integer](a T) bool

IsEven returns true iff the argument is an even number

func IsFalse

func IsFalse(b bool) bool

IsFalse checks if a bool is false, for declarative testing

func IsFunc

func IsFunc[T any](val T, f func(T, T) bool) func(T) bool

IsFunc wraps an equivalence predicate for a value of non-comparable type

func IsNil

func IsNil[T Niler[*any, any]](arg T) bool

IsNil checks if some value is nil

func IsOdd

func IsOdd[T rules.Integer](a T) bool

IsOdd returns true iff the argument is an odd number

func IsTrue

func IsTrue(b bool) bool

IsTrue checks if a bool is true, for declarative testing

func Isnt

func Isnt[T comparable](val T) func(T) bool

Isnt creates an anti-equivalence predicate for a value

func Le

func Le[T rules.Ordered](a, b T) bool

Le calls "<="

func Len

func Len[T any](arg []T) int

Len returns the length of a slice

func Lsb

func Lsb[T rules.Int](arg T) bool

Lsb checks if Least Significant Bit equals 1

func Lt

func Lt[T rules.Ordered](a, b T) bool

Lt calls "<"

func Method

func Method[L, R, T any](val L, f func(L, R) T) func(R) T

Method returns a detatched method for some value calling the given binary operator with it as the left operand similar to Bind except the value is the left operand see Bind for more info

func MethodEach

func MethodEach[L, R, T any](fn func(L, R) T, vals ...L) []func(R) T

MethodEach creates a collection of unary operators from a binary operator and a collection of operands

func MethodOp

func MethodOp[T, U, V, L, R any](op func(L, R) U, f func(func(L, R) U, T) V) func(T) V

MethodOp returns a detatched method for some binary operator calling the given binary operator with it as the left operand similar to BindVal except the value is the left operand see BindOp for more info

func MethodVar

func MethodVar[R, L, T any](v func() L, f func(L, R) T) func(R) T

MethodVar returns a detatched method for some variable calling the given binary operator with it as the left operand similar to BindVal except the value is the left operand see BindVar for more info

func Move

func Move[T any](dst, src *[]T) int

Move moves elements from a source slice into a destination slice with respect to its capacity. The source and destination may overlap. It is a no-op if the destination's length equals its capacity. Returns the number of elements copied, which will be:

		0				if src is empty or dst is full
cap(dst) - len(dst); 	unless
cap(dst) - len(src)		is smaller but non-negative

func Msb

func Msb[T rules.Int](arg T) bool

Msb checks if Most Significant Bit equals 1

func Must

func Must[I, O any](f func(I) (O, error)) func(I) O

func Ne

func Ne[T comparable](a, b T) bool

Ne compares two values for inequality

func Neither

func Neither[T any](one, two func(T) bool) func(T) bool

Neither offers the !AND gate

func New

func New[T any]() *T

New returns a pointer to a new instance of the given type

func Not

func Not[T any](pred func(T) bool) func(T) bool

Not returns the negation of a predicate

func NotBoth

func NotBoth[T any](one, two func(T) bool) func(T) bool

NotBoth offers the XOR gate

func NotNil

func NotNil[T Niler[*any, any]](arg T) bool

NotNil checks if some value is nil

func Nothing

func Nothing(args ...any)

Nothing is a place holder for imports so that you can run a script even though you've removed all references to an import

func One

func One[T any](preds ...func(T) bool) func(T) bool

Any XOR-concatenates a sequence of boolean operators with of a shared type If no argument is given, the returned predicate will check if its argument's pointer is nil

func Onead

func Onead[I, O any](f func(...I) O) func(I) O

Onead transforms a variadic function to a 1-adic

func Or

func Or[L, R any](one func(L) bool, two func(R) bool) func(L, R) bool

Or returns the || gate for non-boolean types

func ParseBin

func ParseBin[T rules.Real](s string) T

ParseBin parses a base 2 integer-string into the given type under the hood, it's a panicky-wrapper on strconv.ParseInt

func ParseFloat

func ParseFloat[T rules.Real](s string) T

ParseFloat parses a decimal-string into the given type under the hood, it's a panicky-wrapper on strconv.ParseInt

func ParseHex

func ParseHex[T rules.Real](s string) T

ParseHex parses a base 16 integer-string into the given type under the hood, it's a panicky-wrapper on strconv.ParseInt

func ParseInt

func ParseInt[T rules.Real](s string) T

ParseInt parses a base 10 integer-string into the given type under the hood, it's a panicky-wrapper on strconv.ParseInt

func ParseIntn

func ParseIntn[T rules.Real](n int, s string) T

ParseIntn parses an integer-string of arbitrary base into the given type under the hood, it's a panicky-wrapper on strconv.ParseInt

func Pipe

func Pipe[L, R, T any](one func(L) R, two func(R) T) func(L) T

Pipe concatenates two unary operators

func Pointer

func Pointer[T any](p T) *T

Pointer returns a pointer to the given value

func Pred

func Pred[T, U any](pred func(T) bool, whenTrue, whenFalse U) func(T) U

func Printer

func Printer() func(...any) (int, error)

Printer returns a closure that prints to the given writer

func Printerf

func Printerf(format string) func(...any) (int, error)

Printerf returns a closure that prints a format string to the given writer

func Printerln

func Printerln() func(...any) (int, error)

Printerln returns a closure that prints a line to the given writer

func Real

func Real[N rules.Real, C rules.Complex](arg C) N

Real extracts the real part of a complex number

func Returner

func Returner[T any](arg T) T

Returner is a place holder for pipelines that depend on casters

func Sizeof

func Sizeof[T any]() uintptr

Sizeof returns the size, in bits, of an instance of the given type

func Slicead

func Slicead[I, O any](f func(...I) O) func([]I) O

Slicead transforms a variadic function to one that accepts a slice

func Ternary

func Ternary[T any](pred bool, whenTrue, whenFalse T) T

Ternary reduces the if-else statement to a one-liner

func ToBool

func ToBool[T comparable](arg T) bool

ToBool returns true iff the argument is non-zero a string is zero iff it's length is zero

func ToBoolLener

func ToBoolLener[Seq rules.Lener[K, V], K comparable, V any](arg Seq) bool

ToBoolIter converts indexable types to booleans if it's length is zero, it is false

func ToByte

func ToByte[T rules.Integer](arg T) byte

ToByte casts the argument to a byte value

func ToComplex128

func ToComplex128[T rules.Real](arg T) complex128

ToComplex128 casts the argument to a complex128 value

func ToComplex64

func ToComplex64[T rules.Real](arg T) complex64

ToComplex64 casts the argument to a complex64 value

func ToFloat32

func ToFloat32[T rules.Integer](arg T) float32

ToFloat32 casts the argument to a float32 value

func ToFloat64

func ToFloat64[T rules.Integer](arg T) float64

ToFloat64 casts the argument to a float64 value

func ToInt

func ToInt[T rules.Integer](arg T) int

ToInt casts the argument to a int value

func ToInt16

func ToInt16[T rules.Integer](arg T) int16

ToInt16 casts the argument to a int16 value

func ToInt32

func ToInt32[T rules.Integer](arg T) int32

ToInt32 casts the argument to a int32 value

func ToInt64

func ToInt64[T rules.Integer](arg T) int64

ToInt64 casts the argument to a int64 value

func ToInt8

func ToInt8[T rules.Integer](arg T) int8

ToInt8 casts the argument to a int8 value

func ToRune

func ToRune[T rules.Integer](arg T) rune

ToRune casts the argument to a rune value

func ToString

func ToString[T any](arg T) string

ToString casts the argument to a string value

func ToString2

func ToString2[T any](arg T) string

ToString2 casts the argument to a string2 value with type information

func ToUint

func ToUint[T rules.Integer](arg T) uint

ToUint casts the argument to a uint value

func ToUint16

func ToUint16[T rules.Integer](arg T) uint16

ToUint16 casts the argument to a uint16 value

func ToUint32

func ToUint32[T rules.Integer](arg T) uint32

ToUint32 casts the argument to a uint32 value

func ToUint64

func ToUint64[T rules.Integer](arg T) uint64

ToUint64 casts the argument to a uint64 value

func ToUint8

func ToUint8[T rules.Integer](arg T) uint8

ToUint8 casts the argument to a uint8 value

func ToUintptr

func ToUintptr[T rules.Integer](arg T) uintptr

ToUintptr casts the argument to a uintptr value

func Typeis

func Typeis[want, have any](arg have) bool

Typeis checks if a given value has wanted type

func Value

func Value[T any](p *T) T

Value returns the value to the given pointer

func Variad

func Variad[I, O any](f func([]I) O) func(...I) O

Variad transforms a variadic function to one that accepts a slice

func WrapAny

func WrapAny[T, L, R any](fn func(L, R)) func(L, R) *T

func Xor

func Xor[L, R any](one func(L) bool, two func(R) bool) func(L, R) bool

Or returns the && gate for non-boolean types

Types

type BinOp

type BinOp[L, R, T any] func(L, R) T

type BinVar

type BinVar[L, R any] func() (L, R)

type Caster

type Caster[I, O any] func(I) O

type Niler

type Niler[K comparable, V any] interface {
	~*V | ~[]V | ~map[K]V | ~chan V //| error // compiler: cannot use error in union (error contains methods)
}

Niler is a constraint satisfied by nullable types

type Op

type Op[T any] func(T) T

type Option

type Option[T any] BinVar[T, error]

type TernOp

type TernOp[T any] func(bool, T, T) T

type Var

type Var[T any] func() T

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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