partial

package
v0.0.0-...-d5aba35 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 3 Imported by: 0

README

Partial function argument binders

Usage:

Bind[x_y][r[z]](Func, ArgToBind) where:

  • x - number of args to Func
  • y - the yth number of arg of Func to bind. y <= x
  • z - number of return values of Func

Currently supports binding only 1 argument, to a function of maximum 4 arguments and 2 return values.

For example:

func Add(a, b int) int {
    return a + b
}

func main() {
    AddTo5 := Bind2_1r(Add, 5)  // binds 5 to the 1st argument of Add(). Add() has 2 arguments and a return value
    fmt.Println(AddTo5(10))     // prints 15
}

Will consider implementing more flexible forms like Bind__xxr, where every _ is an arguments to bind and every x to bypass.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[T1 any](f func(T1), t1 T1) func()

func Bind2_1

func Bind2_1[T1, T2 any](f func(T1, T2), t1 T1) func(T2)

func Bind2_1r

func Bind2_1r[T1, T2, R any](f func(T1, T2) R, t1 T1) func(T2) R

func Bind2_1r2

func Bind2_1r2[T1, T2, R, R2 any](f func(T1, T2) (R, R2), t1 T1) func(T2) (R, R2)

func Bind2_2

func Bind2_2[T1, T2 any](f func(T1, T2), t2 T2) func(T1)

func Bind2_2r

func Bind2_2r[T1, T2, R any](f func(T1, T2) R, t2 T2) func(T1) R

func Bind2_2r2

func Bind2_2r2[T1, T2, R, R2 any](f func(T1, T2) (R, R2), t2 T2) func(T1) (R, R2)

func Bind3_1

func Bind3_1[T1, T2, T3 any](f func(T1, T2, T3), t1 T1) func(T2, T3)

func Bind3_1r

func Bind3_1r[T1, T2, T3, R any](f func(T1, T2, T3) R, t1 T1) func(T2, T3) R

func Bind3_1r2

func Bind3_1r2[T1, T2, T3, R, R2 any](f func(T1, T2, T3) (R, R2), t1 T1) func(T2, T3) (R, R2)

func Bind3_2

func Bind3_2[T1, T2, T3 any](f func(T1, T2, T3), t2 T2) func(T1, T3)

func Bind3_2r

func Bind3_2r[T1, T2, T3, R any](f func(T1, T2, T3) R, t2 T2) func(T1, T3) R

func Bind3_2r2

func Bind3_2r2[T1, T2, T3, R, R2 any](f func(T1, T2, T3) (R, R2), t2 T2) func(T1, T3) (R, R2)

func Bind3_3

func Bind3_3[T1, T2, T3 any](f func(T1, T2, T3), t3 T3) func(T1, T2)

func Bind3_3r

func Bind3_3r[T1, T2, T3, R any](f func(T1, T2, T3) R, t3 T3) func(T1, T2) R

func Bind3_3r2

func Bind3_3r2[T1, T2, T3, R, R2 any](f func(T1, T2, T3) (R, R2), t3 T3) func(T1, T2) (R, R2)

func Bind4_1

func Bind4_1[T1, T2, T3, T4 any](f func(T1, T2, T3, T4), t1 T1) func(T2, T3, T4)

func Bind4_1r

func Bind4_1r[T1, T2, T3, T4, R any](f func(T1, T2, T3, T4) R, t1 T1) func(T2, T3, T4) R

func Bind4_1r2

func Bind4_1r2[T1, T2, T3, T4, R, R2 any](f func(T1, T2, T3, T4) (R, R2), t1 T1) func(T2, T3, T4) (R, R2)

func Bind4_2

func Bind4_2[T1, T2, T3, T4 any](f func(T1, T2, T3, T4), t2 T2) func(T1, T3, T4)

func Bind4_2r

func Bind4_2r[T1, T2, T3, T4, R any](f func(T1, T2, T3, T4) R, t2 T2) func(T1, T3, T4) R

func Bind4_2r2

func Bind4_2r2[T1, T2, T3, T4, R, R2 any](f func(T1, T2, T3, T4) (R, R2), t2 T2) func(T1, T3, T4) (R, R2)

func Bind4_3

func Bind4_3[T1, T2, T3, T4 any](f func(T1, T2, T3, T4), t3 T3) func(T1, T2, T4)

func Bind4_3r

func Bind4_3r[T1, T2, T3, T4, R any](f func(T1, T2, T3, T4) R, t3 T3) func(T1, T2, T4) R

func Bind4_3r2

func Bind4_3r2[T1, T2, T3, T4, R, R2 any](f func(T1, T2, T3, T4) (R, R2), t3 T3) func(T1, T2, T4) (R, R2)

func Bind4_4

func Bind4_4[T1, T2, T3, T4 any](f func(T1, T2, T3, T4), t4 T4) func(T1, T2, T3)

func Bind4_4r

func Bind4_4r[T1, T2, T3, T4, R any](f func(T1, T2, T3, T4) R, t4 T4) func(T1, T2, T3) R

func Bind4_4r2

func Bind4_4r2[T1, T2, T3, T4, R, R2 any](f func(T1, T2, T3, T4) (R, R2), t4 T4) func(T1, T2, T3) (R, R2)

func Bindr

func Bindr[T1, R any](f func(T1) R, t1 T1) func() R

func Bindr2

func Bindr2[T1, R, R2 any](f func(T1) (R, R2), t1 T1) func() (R, R2)

Types

type Func

type Func[F any] struct {
	// contains filtered or unexported fields
}

func NewFunc

func NewFunc[F any](f F) *Func[F]

func (*Func[F]) Equals

func (me *Func[F]) Equals(other any) bool

Equals compares the function addresses of the me and other

func (*Func[F]) Get

func (me *Func[F]) Get() F

type FuncOrMethod

type FuncOrMethod[F any] interface {
	Get() F
	Equals(other any) bool
}

type Handler

type Handler[F any] struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler[F any]() *Handler[F]

func (*Handler[F]) AddFunc

func (me *Handler[F]) AddFunc(f F) (subscriber any)

add a function to the handler (even if it is already added)

func (*Handler[F]) AddMethod

func (me *Handler[F]) AddMethod(f F, receiver any) (subscriber any)

add a method to the handler (even if it is already added)

func (*Handler[F]) Get

func (me *Handler[F]) Get() []F

get all functions and methods

func (*Handler[F]) Remove

func (me *Handler[F]) Remove(subscriber any)

remove a function or method from the handler. if subscriber was added multiple times, all of it will be removed

type Method

type Method[F any, O any] struct {
	Func[F]
	// contains filtered or unexported fields
}

func NewMethod

func NewMethod[F any, O any](f F, receiver O) *Method[F, O]

NewMethod creates a new Method. f must be a method of receiver. It will not panic if it's not. But the receiver is used to check if 2 Methods are the same

func NewMethodStrict

func NewMethodStrict[A any, R any, O any](f func(O, A) R, receiver O) *Method[func(A) R, O]

NewMethodStrict creates a new Method. This is a type checked version of NewMethod. But its use case is limited to 1 and only 1 arg+result.

func (*Method[F, O]) Equals

func (me *Method[F, O]) Equals(other any) bool

Jump to

Keyboard shortcuts

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