fpgo

package module
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 11 Imported by: 0

README

fpGo

tag Go Report Card codecov Travis CI Build Status GoDoc

license stars forks

Monad, Functional Programming features for Golang

Active Branches:

For Generics version(>=go1.18):generics

go get github.com/TeaEntityLab/fpGo/v2

For NonGenerics version(<=go1.17):non-generics

go get github.com/TeaEntityLab/fpGo

Why

I love functional programing, Rx-style coding, and Optional usages.

However it's hard to implement them in Golang, and there're few libraries to achieve parts of them.

Thus I implemented fpGo. I hope you would like it :)

Features

  • Optional/Maybe

  • Monad, Rx-like

  • Publisher

  • Pattern matching

  • Fp functions

  • Java8Stream-like Collection

  • Queue (LinkedListQueue/ChannelQueue/BufferedChannelQueue/ConcurrentQueue)

  • PythonicGenerator-like Coroutine(yield/yieldFrom)

  • Akka/Erlang-like Actor model(send/receive/spawn/states)

  • network/SimpleHTTP inspired by Retrofit

  • worker/WorkerPool inspired by JavaExecutorService & goroutine pool libs

Special thanks

Usage

Optional (IsPresent/IsNil, Or, Let)

var m MaybeDef[interface{}]
var orVal int
var boolVal bool

// IsPresent(), IsNil()
m = Maybe.Just(1)
boolVal = m.IsPresent() // true
boolVal = m.IsNil() // false
m = Maybe.Just(nil)
boolVal = m.IsPresent() // false
boolVal = m.IsNil() // true

// Or()
m = Maybe.Just(1)
fmt.Println((m.Or(3))) // 1
m = Maybe.Just(nil)
fmt.Println((m.Or(3))) // 3

// Let()
var letVal int
letVal = 1
m = Maybe.Just(1)
m.Let(func() {
  letVal = 2
})
fmt.Println(letVal) // letVal would be 2

letVal = 1
m = Maybe.Just(nil)
m.Let(func() {
  letVal = 3
})
fmt.Println(letVal) // letVal would be still 1

MonadIO (RxObserver-like)

Example:

var m *MonadIODef[interface{}]
var actualInt int

m = MonadIO.Just(1)
actualInt = 0
m.Subscribe(Subscription[interface{}]{
  OnNext: func(in interface{}) {
    actualInt, _ = Maybe.Just(in).ToInt()
  },
})
fmt.Println(actualInt) // actualInt would be 1

m = MonadIO.Just(1).FlatMap(func(in interface{}) *MonadIODef[interface{}] {
  v, _ := Maybe.Just(in).ToInt()
  return MonadIO.Just(v + 1)
})
actualInt = 0
m.Subscribe(Subscription[interface{}]{
  OnNext: func(in interface{}) {
    actualInt, _ = Maybe.Just(in).ToInt()
  },
})
fmt.Println(actualInt) // actualInt would be 2

Stream (inspired by Collection libs)

Example(Generics):

var s *StreamDef[int]
var tempString = ""

s = StreamFromArray([]int{}).Append(1, 1).Extend(StreamFromArray([]int{2, 3, 4}))
tempString = ""
for _, v := range s.ToArray() {
  tempString += Maybe.Just(v).ToMaybe().ToString()
}
fmt.Println(tempString) // tempString would be "11234"
s = s.Distinct()
tempString = ""
for _, v := range s.ToArray() {
  tempString += Maybe.Just(v).ToMaybe().ToString()
}
fmt.Println(tempString) // tempString would be "1234"

Example(Non-Generics/interface{}):

var s *StreamForInterfaceDef
var tempString string

s = StreamForInterface.FromArrayInt([]int{}).Append(1, 1).Extend(StreamForInterface.FromArrayInt([]int{2, 3, 4})).Extend(StreamForInterface.FromArray([]interface{}{nil})).Extend(nil)
tempString = ""
for _, v := range s.ToArray() {
  tempString += Maybe.Just(v).ToMaybe().ToString()
}
fmt.Println(tempString) // tempString would be "11234<nil>"
s = s.Distinct()
tempString = ""
for _, v := range s.ToArray() {
  tempString += Maybe.Just(v).ToMaybe().ToString()
}
fmt.Println(tempString) // tempString would be "1234<nil>"
s = s.FilterNotNil()
tempString = ""
for _, v := range s.ToArray() {
  tempString += Maybe.Just(v).ToMaybe().ToString()
}
fmt.Println(tempString) // tempString would be "1234"

Queue(LinkedListQueue/ChannelQueue/BufferedChannelQueue/ConcurrentQueue) (inspired by Collection libs)

LinkedListQueue(Shift/Unshift/Push/Pop), ConcurrentQueue(inspired by Java)

Example:

var queue Queue[int]
var stack Stack[int]
var err error
var result int

linkedListQueue := NewLinkedListQueue[int]()
queue = linkedListQueue
stack = linkedListQueue
concurrentQueue := NewConcurrentQueue[int](queue)

// As a Queue, Put(val) in the TAIL and Take() in the HEAD
err = queue.Offer(1)
err = queue.Offer(2)
err = queue.Offer(3)
result, err = queue.Poll() // Result should be 1
result, err = queue.Poll() // Result should be 2
result, err = queue.Poll() // Result should be 3
result, err = queue.Poll() // Err: ErrQueueIsEmpty

// As a Stack, Push(val) & Pop() in the TAIL.
err = stack.Push(1)
err = stack.Push(2)
err = stack.Push(3)
result, err = stack.Pop() // Result should be 3
result, err = stack.Pop() // Result should be 2
result, err = stack.Pop() // Result should be 1
result, err = stack.Pop() // Err: ErrStackIsEmpty
BufferedChannelQueue(Offer/Take/TakeWithTimeout)

Example:

var err error
var result int
var timeout time.Duration

bufferedChannelQueue := NewBufferedChannelQueue[int](3, 10000, 100).
  SetLoadFromPoolDuration(time.Millisecond / 10).
  SetFreeNodeHookPoolIntervalDuration(1 * time.Millisecond)

err = queue.Offer(1)
err = queue.Offer(2)
err = queue.Offer(3)
timeout = 1 * time.Millisecond
result, err = bufferedChannelQueue.TakeWithTimeout(timeout) // Result should be 1
result, err = bufferedChannelQueue.TakeWithTimeout(timeout) // Result should be 2
result, err = bufferedChannelQueue.TakeWithTimeout(timeout) // Result should be 3

Actor (inspired by Akka/Erlang)

Actor common(send/receive/spawn/states)

Example:

actual := 0
// Channel for results
resultChannel := make(chan interface{}, 1)
// Message CMDs
cmdSpawn := "spawn"
cmdShutdown := "shutdown"
// Testee
actorRoot := Actor.New(func(self *ActorDef[interface{}], input interface{}) {
  // SPAWN: for ROOT
  if input == cmdSpawn {
    self.Spawn(func(self *ActorDef[interface{}], input interface{}) {
      // SHUTDOWN: for Children
      if input == cmdShutdown {
        self.Close()
        return
      }

      // INT cases: Children
      val, _ := Maybe.Just(input).ToInt()
      resultChannel <- val * 10
    })
    return
  }
  // SHUTDOWN: for ROOT
  if input == cmdShutdown {
    for _, child := range self.children {
      child.Send(cmdShutdown)
    }
    self.Close()

    close(resultChannel)
    return
  }

  // INT cases: ROOT
  intVal, _ := Maybe.Just(input).ToInt()
  if intVal > 0 {
    for _, child := range self.children {
      child.Send(intVal)
    }
  }
})

// Sequential Send messages(async)
go func() {
  actorRoot.Send(cmdSpawn)
  actorRoot.Send(10)
  actorRoot.Send(cmdSpawn)
  actorRoot.Send(20)
  actorRoot.Send(cmdSpawn)
  actorRoot.Send(30)
}()

i := 0
for val := range resultChannel {
  intVal, _ := Maybe.Just(val).ToInt()
  actual += intVal

  i++
  if i == 5 {
    go actorRoot.Send(cmdShutdown)
  }
}

// Result would be 1400 (=10*10+20*10+20*10+30*10+30*10+30*10)
fmt.Println(actual)
Actor Ask (inspired by Akka/Erlang)
actorRoot := Actor.New(func(self *ActorDef[interface{}], input interface{}) {
    // Ask cases: ROOT
    switch val := input.(type) {
    case *AskDef[interface{}, int]:
        intVal, _ := Maybe.Just(val.Message).ToInt()

        // NOTE If negative, hanging for testing Ask.timeout
        if intVal < 0 {
            break
        }

        val.Reply(intVal * 10)
        break
    }
})

// var timer *time.Timer
var timeout time.Duration
timeout = 10 * time.Millisecond

// Normal cases
// Result would be 10
actual = AskNewGenerics[interface{}, int](1).AskOnce(actorRoot)
// Ask with Timeout
// Result would be 20
actual, _ = AskNewGenerics[interface{}, int](2).AskOnceWithTimeout(actorRoot, timeout)
// Ask channel
// Result would be 30
ch := AskNewGenerics[interface{}, int](3).AskChannel(actorRoot)
actual = <- ch
close(ch)

// Timeout cases
// Result would be 0 (zero value, timeout)
actual, err = AskNewGenerics[interface{}, int](-1).AskOnceWithTimeout(actorRoot, timeout)

Compose

Example:

var fn01 = func(args ...int) []int {
  val := args[0]
  return SliceOf(val + 1)
}
var fn02 = func(args ...int) []int {
  val := args[0]
  return SliceOf(val + 2)
}
var fn03 = func(args ...int) []int {
  val := args[0]
  return SliceOf(val + 3)
}

// Result would be 6
result := Compose(fn01, fn02, fn03)((0))[0]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConversionUnsupported Conversion Unsupported
	ErrConversionUnsupported = errors.New("unsupported")
	// ErrConversionNil Conversion Nil
	ErrConversionNil = errors.New("<nil>")
	// ErrConversionNil Conversion Size Overflow
	ErrConversionSizeOverflow = errors.New("size overflow")
)
View Source
var (
	// ErrQueueIsEmpty Queue Is Empty
	ErrQueueIsEmpty = errors.New("queue is empty")
	// ErrQueueIsFull Queue Is Full
	ErrQueueIsFull = errors.New("queue is full")
	// ErrQueueIsClosed Queue Is Closed
	ErrQueueIsClosed = errors.New("queue is closed")
	// ErrQueueTakeTimeout Queue Take Timeout
	ErrQueueTakeTimeout = errors.New("queue take timeout")
	// ErrQueuePutTimeout Queue Put Timeout
	ErrQueuePutTimeout = errors.New("queue put timeout")

	// ErrStackIsEmpty Stack Is Empty
	ErrStackIsEmpty = errors.New("stack is empty")
	// ErrStackIsFull Stack Is Full
	ErrStackIsFull = errors.New("stack is full")
)
View Source
var ErrActorAskTimeout = fmt.Errorf("ErrActorAskTimeout")
View Source
var Maybe someDef[interface{}]

Maybe Maybe utils instance

View Source
var None = noneDef{someDef[any]{/* contains filtered or unexported fields */}}

None None utils instance

Functions

func CompareToOrdered

func CompareToOrdered[T Ordered](a, b T) int

CompareToOrdered A general Compare function for Ordered

func Compose

func Compose[T any](fnList ...func(...T) []T) func(...T) []T

Compose Compose the functions from right to left (Math: f(g(x)) Compose: Compose(f, g)(x))

func ComposeInterface

func ComposeInterface(fnList ...func(...interface{}) []interface{}) func(...interface{}) []interface{}

ComposeInterface Compose the functions from right to left (Math: f(g(x)) Compose: Compose(f, g)(x))

func Concat

func Concat[T any](mine []T, slices ...[]T) []T

Concat Concat slices

func CurryParam1

func CurryParam1[T any, R any, A any](fn func(A, ...T) R, a A) func(...T) R

CurryParam1 Curry for 1 Param (for currying general fp functions simply)

func CurryParam1ForSlice1

func CurryParam1ForSlice1[T any, R any, A any](fn func(A, []T) R, a A) func(...T) R

CurryParam1ForSlice1 Curry for 1 Param (for currying general fp functions simply)

func CurryParam2

func CurryParam2[T any, R any, A any, B any](fn func(A, B, ...T) R, a A, b B) func(...T) R

CurryParam2 Curry for 2 Params (for currying general fp functions simply)

func CurryParam3

func CurryParam3[T any, R any, A any, B any, C any](fn func(A, B, C, ...T) R, a A, b B, c C) func(...T) R

CurryParam3 Curry for 3 Params (for currying general fp functions simply)

func CurryParam4

func CurryParam4[T any, R any, A any, B any, C any, D any](fn func(A, B, C, D, ...T) R, a A, b B, c C, d D) func(...T) R

CurryParam4 Curry for 4 Params (for currying general fp functions simply)

func CurryParam5

func CurryParam5[T any, R any, A any, B any, C any, D any, E any](fn func(A, B, C, D, E, ...T) R, a A, b B, c C, d D, e E) func(...T) R

CurryParam5 Curry for 5 Params (for currying general fp functions simply)

func CurryParam6

func CurryParam6[T any, R any, A any, B any, C any, D any, E any, F any](fn func(A, B, C, D, E, F, ...T) R, a A, b B, c C, d D, e E, f F) func(...T) R

CurryParam6 Curry for 6 Params (for currying general fp functions simply)

func Dedupe

func Dedupe[T comparable](list ...T) []T

Dedupe Returns a new list removing consecutive duplicates in list.

func Difference

func Difference[T comparable](arrList ...[]T) []T

Difference returns a set that is the first set without elements of the remaining sets repeated value within list parameter will be ignored

func Distinct

func Distinct[T comparable](list ...T) []T

Distinct removes duplicates.

Example

list := []int{8, 2, 8, 0, 2, 0}
Distinct(list...) // returns [8, 2, 0]

func DistinctForInterface

func DistinctForInterface(list ...interface{}) []interface{}

DistinctForInterface removes duplicates.

Example

list := []interface{}{8, 2, 8, 0, 2, 0}
DistinctForInterface(list...) // returns [8, 2, 0]

func DistinctRandom

func DistinctRandom[T comparable](list ...T) []T

DistinctRandom removes duplicates.(RandomOrder)

func Drop

func Drop[T any](count int, list ...T) []T

Drop drops N item(s) from the list and returns new list. Returns empty list if there is only one item in the list or list empty

func DropEq

func DropEq[T comparable](num T, list ...T) []T

DropEq returns a new list after dropping the given item

Example:

DropEq(1, 1, 2, 3, 1) // returns [2, 3]

func DropLast

func DropLast[T any](count int, list ...T) []T

DropLast drops last N item(s) from the list and returns new list. Returns empty list if there is only one item in the list or list empty

func DropWhile

func DropWhile[T any](f Predicate[T], list ...T) []T

DropWhile drops the items from the list as long as condition satisfies.

Takes two inputs

  1. Function: takes one input and returns boolean
  2. list

Returns:

	New List.
 Empty list if either one of arguments or both of them are nil

Example: Drops even number. Returns the remaining items once odd number is found in the list.

DropWhile(isEven, 4, 2, 3, 4, 5) // Returns [3, 4, 5]

func isEven(num int) bool {
	return num%2 == 0
}

func DuplicateMap

func DuplicateMap[T comparable, R any](input map[T]R) map[T]R

DuplicateMap Return a new Map

func DuplicateMapForInterface

func DuplicateMapForInterface[R any](input map[interface{}]R) map[interface{}]R

DuplicateMapForInterface Return a new Map

func DuplicateSlice

func DuplicateSlice[T any](list []T) []T

DuplicateSlice Return a new Slice

func Either

func Either(value interface{}, patterns ...Pattern) interface{}

Either Match Pattern list and return the effect() result of the matching Pattern

func Every

func Every[T any](f Predicate[T], list ...T) bool

Every returns true if supplied function returns logical true for every item in the list

Example:

Every(even, 8, 2, 10, 4) // Returns true

func isEven(num int) bool {
	return num%2 == 0
}

Every(even) // Returns false Every(nil) // Returns false

func Exists

func Exists[T comparable](input T, list ...T) bool

Exists checks if given item exists in the list

Example:

Exists(8, 8, 2, 10, 4) // Returns true
Exists(8) // Returns false

func ExistsForInterface

func ExistsForInterface(input interface{}, list ...interface{}) bool

ExistsForInterface checks if given item exists in the list

Example:

ExistsForInterface(8, 8, 2, 10, 4) // Returns true
ExistsForInterface(8) // Returns false

func Filter

func Filter[T any](fn func(T, int) bool, input ...T) []T

Filter Filter the values by the given predicate function (predicate func, slice)

func Flatten

func Flatten[T any](list ...[]T) []T

Flatten creates a new slice where one level of nested elements are unnested

func GroupBy

func GroupBy[T any, R comparable](grouper TransformerFunctor[T, R], list ...T) map[R][]T

GroupBy creates a map where the key is a group identifier and the value is a slice with the elements that have the same identifer

func Head[T any](list ...T) T

Head returns first element of a slice

func Intersection

func Intersection[T comparable](inputList ...[]T) []T

Intersection return a set that is the intersection of the input sets repeated value within list parameter will be ignored

func IntersectionForInterface

func IntersectionForInterface(inputList ...[]interface{}) []interface{}

IntersectionForInterface return a set that is the intersection of the input sets repeated value within list parameter will be ignored

func IntersectionMapByKey

func IntersectionMapByKey[T comparable, R any](inputList ...map[T]R) map[T]R

IntersectionMapByKey return a set that is the intersection of the input sets

func IntersectionMapByKeyForInterface

func IntersectionMapByKeyForInterface[R any](inputList ...map[interface{}]R) map[interface{}]R

IntersectionMapByKeyForInterface return a set that is the intersection of the input sets

func IsDistinct

func IsDistinct[T comparable](list ...T) bool

IsDistinct returns true if no two of the arguments are =

func IsEqual

func IsEqual[T comparable](list1, list2 []T) bool

IsEqual Returns true if both list are equal else returns false

func IsEqualMap

func IsEqualMap[T comparable, R comparable](map1, map2 map[T]R) bool

IsEqualMap Returns true if both maps are equal else returns false

func IsNeg

func IsNeg[T Numeric](v T) bool

IsNeg Returns true if num is less than zero, else false

func IsNil

func IsNil(obj interface{}) bool

IsNil Check is it nil

func IsPos

func IsPos[T Numeric](v T) bool

IsPos Returns true if num is great than zero, else false

func IsPtr

func IsPtr(obj interface{}) bool

IsPtr Check is it a Ptr

func IsSubset

func IsSubset[T comparable](list1, list2 []T) bool

IsSubset returns true or false by checking if set1 is a subset of set2 repeated value within list parameter will be ignored

func IsSubsetForInterface

func IsSubsetForInterface(list1, list2 []interface{}) bool

IsSubsetForInterface returns true or false by checking if set1 is a subset of set2 repeated value within list parameter will be ignored

func IsSubsetMapByKey

func IsSubsetMapByKey[T comparable, R any](item1, item2 map[T]R) bool

IsSubsetMapByKey returns true or false by checking if set1 is a subset of set2

func IsSubsetMapByKeyForInterface

func IsSubsetMapByKeyForInterface[R any](item1, item2 map[interface{}]R) bool

IsSubsetMapByKeyForInterface returns true or false by checking if set1 is a subset of set2

func IsSuperset

func IsSuperset[T comparable](list1, list2 []T) bool

IsSuperset returns true or false by checking if set1 is a superset of set2 repeated value within list parameter will be ignored

func IsSupersetForInterface

func IsSupersetForInterface(list1, list2 []interface{}) bool

IsSupersetForInterface returns true or false by checking if set1 is a superset of set2 repeated value within list parameter will be ignored

func IsSupersetMapByKey

func IsSupersetMapByKey[T comparable, R any](item1, item2 map[T]R) bool

IsSupersetMapByKey returns true or false by checking if set1 is a superset of set2

func IsSupersetMapByKeyForInterface

func IsSupersetMapByKeyForInterface[R any](item1, item2 map[interface{}]R) bool

IsSupersetMapByKeyForInterface returns true or false by checking if set1 is a superset of set2

func IsZero

func IsZero[T Numeric](v T) bool

IsZero Returns true if num is zero, else false

func Keys

func Keys[T comparable, R any](m map[T]R) []T

Keys returns a slice of map's keys

func KeysForInterface

func KeysForInterface[R any](m map[interface{}]R) []interface{}

KeysForInterface returns a slice of map's keys

func Kind

func Kind(obj interface{}) reflect.Kind

Kind Get Kind by reflection

func MakeNumericReturnForParam1ReturnBool1

func MakeNumericReturnForParam1ReturnBool1[T any, R Numeric](fn func(T) bool) func(...T) []R

MakeNumericReturnForParam1ReturnBool1 Make Numeric 1 bool Return (for compose() general fp functions simply)

func MakeNumericReturnForSliceParamReturnBool1

func MakeNumericReturnForSliceParamReturnBool1[T any, R Numeric](fn func([]T) bool) func(...T) []R

MakeNumericReturnForSliceParamReturnBool1 Make Numeric 1 bool Return (for compose() general fp functions simply)

func MakeNumericReturnForVariadicParamReturnBool1

func MakeNumericReturnForVariadicParamReturnBool1[T any, R Numeric](fn func(...T) bool) func(...T) []R

MakeNumericReturnForVariadicParamReturnBool1 Make Numeric 1 bool Return (for compose() general fp functions simply)

func MakeVariadicParam1

func MakeVariadicParam1[T any, R any](fn func(T) []R) func(...T) []R

MakeVariadicParam1 MakeVariadic for 1 Param (for compose() general fp functions simply)

func MakeVariadicParam2

func MakeVariadicParam2[T any, R any](fn func(T, T) []R) func(...T) []R

MakeVariadicParam2 MakeVariadic for 2 Params (for compose() general fp functions simply)

func MakeVariadicParam3

func MakeVariadicParam3[T any, R any](fn func(T, T, T) []R) func(...T) []R

MakeVariadicParam3 MakeVariadic for 3 Params (for compose() general fp functions simply)

func MakeVariadicParam4

func MakeVariadicParam4[T any, R any](fn func(T, T, T, T) []R) func(...T) []R

MakeVariadicParam4 MakeVariadic for 4 Params (for compose() general fp functions simply)

func MakeVariadicParam5

func MakeVariadicParam5[T any, R any](fn func(T, T, T, T, T) []R) func(...T) []R

MakeVariadicParam5 MakeVariadic for 5 Params (for compose() general fp functions simply)

func MakeVariadicParam6

func MakeVariadicParam6[T any, R any](fn func(T, T, T, T, T, T) []R) func(...T) []R

MakeVariadicParam6 MakeVariadic for 6 Params (for compose() general fp functions simply)

func MakeVariadicReturn1

func MakeVariadicReturn1[T any, R any](fn func(...T) R) func(...T) []R

MakeVariadicReturn1 MakeVariadic for 1 Return value (for compose() general fp functions simply)

func MakeVariadicReturn2

func MakeVariadicReturn2[T any, R any](fn func(...T) (R, R)) func(...T) []R

MakeVariadicReturn2 MakeVariadic for 2 Return values (for compose() general fp functions simply)

func MakeVariadicReturn3

func MakeVariadicReturn3[T any, R any](fn func(...T) (R, R, R)) func(...T) []R

MakeVariadicReturn3 MakeVariadic for 3 Return values (for compose() general fp functions simply)

func MakeVariadicReturn4

func MakeVariadicReturn4[T any, R any](fn func(...T) (R, R, R, R)) func(...T) []R

MakeVariadicReturn4 MakeVariadic for 4 Return values (for compose() general fp functions simply)

func MakeVariadicReturn5

func MakeVariadicReturn5[T any, R any](fn func(...T) (R, R, R, R, R)) func(...T) []R

MakeVariadicReturn5 MakeVariadic for 5 Return values (for compose() general fp functions simply)

func MakeVariadicReturn6

func MakeVariadicReturn6[T any, R any](fn func(...T) (R, R, R, R, R, R)) func(...T) []R

MakeVariadicReturn6 MakeVariadic for 6 Return values (for compose() general fp functions simply)

func Map

func Map[T any, R any](fn TransformerFunctor[T, R], values ...T) []R

Map Map the values to the function from left to right

func MapIndexed

func MapIndexed[T any, R any](fn func(T, int) R, values ...T) []R

MapIndexed Map the values to the function from left to right

func MatchCompType

func MatchCompType(compType CompType, value CompData) bool

MatchCompType Check does the Composite Data match the given SumType

func MatchCompTypeRef

func MatchCompTypeRef(compType CompType, value *CompData) bool

MatchCompTypeRef Check does the Composite Data match the given SumType

func Max

func Max[T Numeric](list ...T) T

Max returns max item from the list. Return 0 if the list is either empty or nil

func Merge

func Merge[T comparable, R any](map1, map2 map[T]R) map[T]R

Merge takes two inputs: map[T]R and map[T]R and merge two maps and returns a new map[T]R.

func MergeForInterface

func MergeForInterface[R any](map1, map2 map[interface{}]R) map[interface{}]R

MergeForInterface takes two inputs: map[T]R and map[T]R and merge two maps and returns a new map[T]R.

func Min

func Min[T Numeric](list ...T) T

Min returns min item from the list. Return 0 if the list is either empty or nil

func MinMax

func MinMax[T Numeric](list ...T) (T, T)

MinMax returns min and max items from the list. Return 0,0 if the list is either empty or nil

func Minus

func Minus[T comparable](set1, set2 []T) []T

Minus all of set1 but not in set2

func MinusForInterface

func MinusForInterface(set1, set2 []interface{}) []interface{}

MinusForInterface all of set1 but not in set2

func MinusMapByKey

func MinusMapByKey[T comparable, R any](set1, set2 map[T]R) map[T]R

MinusMapByKey all of set1 but not in set2

func PMap

func PMap[T any, R any](f TransformerFunctor[T, R], option *PMapOption, list ...T) []R

PMap applies the function(1st argument) on each item in the list and returns a new list.

Order of new list is guaranteed. This feature can be disabled by passing: PMapOption{RandomOrder: true} to gain performance
Run in parallel. no_of_goroutines = no_of_items_in_list or 3rd argument can be passed to fix the number of goroutines.

Takes 3 inputs. 3rd argument is option

  1. Function - takes 1 input
  2. optional argument - PMapOption{FixedPool: <some_number>}
  3. List

func Partition

func Partition[T any](predicate Predicate[T], list ...T) [][]T

Partition splits elements into two groups - one where the predicate is satisfied and one where the predicate is not

func Pipe

func Pipe[T any](fnList ...func(...T) []T) func(...T) []T

Pipe Pipe the functions from left to right

func PipeInterface

func PipeInterface(fnList ...func(...interface{}) []interface{}) func(...interface{}) []interface{}

PipeInterface Pipe the functions from left to right

func Prepend

func Prepend[T any](element T, list []T) []T

Prepend returns the slice with the additional element added to the beginning

func PtrOf

func PtrOf[T any](v T) *T

PtrOf Return Ptr of a value

func Range

func Range[T Numeric](lower, higher T, hops ...T) []T

Range returns a list of range between lower and upper value

Takes 3 inputs

  1. lower limit
  2. Upper limit
  3. Hops (optional)

Returns

List of range between lower and upper value
Empty list if 3rd argument is either 0 or negative number

Example:

Range(-2, 2) // Returns: [-2, -1, 0, 1]
Range(0, 2) // Returns: [0, 1]
Range(3, 7, 2) // Returns: [3, 5]

func Reduce

func Reduce[T any, R any](fn ReducerFunctor[T, R], memo R, input ...T) R

Reduce Reduce the values from left to right(func(memo,val), starting value, slice)

func ReduceIndexed

func ReduceIndexed[T any, R any](fn func(R, T, int) R, memo R, input ...T) R

ReduceIndexed Reduce the values from left to right(func(memo,val,index), starting value, slice)

func Reject

func Reject[T any](fn func(T, int) bool, input ...T) []T

Reject Reject the values by the given predicate function (predicate func, slice)

func Reverse

func Reverse[T any](list ...T) []T

Reverse reverse the list

func SliceOf

func SliceOf[T any](args ...T) []T

SliceOf Return Slice of varargs

func SliceToMap

func SliceToMap[T comparable, R any](defaultValue R, input ...T) map[T]R

SliceToMap Return Slice of varargs

func SliceToMapForInterface

func SliceToMapForInterface[R any](defaultValue R, input ...interface{}) map[interface{}]R

SliceToMapForInterface Return Slice of varargs

func Some

func Some[T any](f Predicate[T], list ...T) bool

Some finds item in the list based on supplied function.

Takes 2 input:

  1. Function
  2. List

Returns:

bool.
True if condition satisfies, else false

Example:

Some(isEven, 8, 2, 10, 4) // Returns true
Some(isEven, 1, 3, 5, 7) // Returns false
Some(nil) // Returns false

func isEven(num int) bool {
	return num%2 == 0
}

func Sort

func Sort[T any](fn Comparator[T], input []T)

Sort Sort items by Comparator

func SortBySortDescriptors

func SortBySortDescriptors[T any](sortDescriptors []SortDescriptor[T], input []T)

SortBySortDescriptors Sort items by sortDescriptors

func SortOrdered

func SortOrdered[T Ordered](ascending bool, input ...T) []T

SortOrdered Sort items by Comparator

func SortOrderedAscending

func SortOrderedAscending[T Ordered](input ...T) []T

SortOrderedAscending Sort items by Comparator

func SortOrderedDescending

func SortOrderedDescending[T Ordered](input ...T) []T

SortOrderedDescending Sort items by Comparator

func SortSlice

func SortSlice[T any](fn Comparator[T], input ...T) []T

SortSlice Sort items by Comparator

func SortedListBySortDescriptors

func SortedListBySortDescriptors[T any](sortDescriptors []SortDescriptor[T], input ...T) []T

SortedListBySortDescriptors Sort items by sortDescriptors and return value

func SplitEvery

func SplitEvery[T any](size int, list ...T) [][]T

SplitEvery returns elements in equal length slices

func Tail

func Tail[T any](list ...T) []T

Tail returns the input slice with all elements except the first element

func Take

func Take[T any](count int, list ...T) []T

Take returns the first n elements of the slice

func TakeLast

func TakeLast[T any](count int, list ...T) []T

TakeLast returns the last n elements of the slice

func Trampoline

func Trampoline[T any](fn func(...T) ([]T, bool, error), input ...T) ([]T, error)

Trampoline Trampoline

func Union

func Union[T comparable](arrList ...[]T) []T

Union return a set that is the union of the input sets repeated value within list parameter will be ignored

func UniqBy

func UniqBy[T any, R comparable](identify TransformerFunctor[T, R], list ...T) []T

UniqBy returns a slice of only unique values based on a comparable identifier

func Values

func Values[T comparable, R any](m map[T]R) []R

Values returns a slice of map's values

func ValuesForInterface

func ValuesForInterface[R any](m map[interface{}]R) []R

ValuesForInterface returns a slice of map's values

func Zip

func Zip[T comparable, R any](list1 []T, list2 []R) map[T]R

Zip takes two inputs: first list of type: []T, second list of type: []T. Then it merges two list and returns a new map of type: map[T]R

Types

type ActorDef

type ActorDef[T any] struct {
	// contains filtered or unexported fields
}

ActorDef[T] Actor model inspired by Erlang/Akka

var Actor ActorDef[interface{}]

Actor Actor utils instance

func ActorNewByOptionsGenerics

func ActorNewByOptionsGenerics[T any](effect func(*ActorDef[T], T), ioCh chan T, context map[string]interface{}) *ActorDef[T]

ActorNewByOptionsGenerics New Actor by its options

func ActorNewGenerics

func ActorNewGenerics[T any](effect func(*ActorDef[T], T)) *ActorDef[T]

ActorNewGenerics New Actor instance

func (*ActorDef[T]) Close

func (actorSelf *ActorDef[T]) Close()

Close Close the Actor

func (*ActorDef[T]) GetChild

func (actorSelf *ActorDef[T]) GetChild(id time.Time) *ActorDef[T]

GetChild Get a child Actor by ID

func (*ActorDef[T]) GetDefault

func (actorSelf *ActorDef[T]) GetDefault() *ActorDef[interface{}]

GetDefault Get Default Actor

func (*ActorDef[T]) GetID

func (actorSelf *ActorDef[T]) GetID() time.Time

GetID Get ID time.Time

func (*ActorDef[T]) GetParent

func (actorSelf *ActorDef[T]) GetParent() *ActorDef[T]

GetParent Get its parent Actor

func (*ActorDef[T]) IsClosed

func (actorSelf *ActorDef[T]) IsClosed() bool

IsClosed Check is Closed

func (*ActorDef[T]) New

func (actorSelf *ActorDef[T]) New(effect func(*ActorDef[T], T)) *ActorDef[T]

New New Actor instance

func (*ActorDef[T]) NewByOptions

func (actorSelf *ActorDef[T]) NewByOptions(effect func(*ActorDef[T], T), ioCh chan T, context map[string]interface{}) *ActorDef[T]

NewByOptions New Actor by its options

func (*ActorDef[T]) Send

func (actorSelf *ActorDef[T]) Send(message T)

Send Send a message to the Actor

func (*ActorDef[T]) Spawn

func (actorSelf *ActorDef[T]) Spawn(effect func(*ActorDef[T], T)) *ActorDef[T]

Spawn Spawn a new Actor with parent(this actor)

type ActorHandle

type ActorHandle[T any] interface {
	Send(message T)
}

ActorHandle A target could send messages

type AskDef

type AskDef[T any, R any] struct {
	Message T
	// contains filtered or unexported fields
}

AskDef[T, R] Ask inspired by Erlang/Akka

var Ask AskDef[interface{}, interface{}]

Ask Ask utils instance

func AskNewByOptionsGenerics

func AskNewByOptionsGenerics[T any, R any](message T, ioCh chan R) *AskDef[T, R]

AskNewByOptionsGenerics New Ask by its options

func AskNewGenerics

func AskNewGenerics[T any, R any](message T) *AskDef[T, R]

AskNewGenerics New Ask instance

func (*AskDef[T, R]) AskChannel

func (askSelf *AskDef[T, R]) AskChannel(target ActorHandle[interface{}]) chan R

AskChannel Sender Ask

func (*AskDef[T, R]) AskOnce

func (askSelf *AskDef[T, R]) AskOnce(target ActorHandle[interface{}]) R

AskOnce Sender Ask

func (*AskDef[T, R]) AskOnceWithTimeout added in v2.2.4

func (askSelf *AskDef[T, R]) AskOnceWithTimeout(target ActorHandle[interface{}], timeout time.Duration) (R, error)

AskOnceWithTimeout Sender Ask with timeout

func (*AskDef[T, R]) New

func (askSelf *AskDef[T, R]) New(message T) *AskDef[T, R]

New New Ask instance

func (*AskDef[T, R]) NewByOptions

func (askSelf *AskDef[T, R]) NewByOptions(message T, ioCh chan R) *AskDef[T, R]

NewByOptions New Ask by its options

func (*AskDef[T, R]) Reply

func (askSelf *AskDef[T, R]) Reply(response R)

Reply Receiver Reply

type AtomBool

type AtomBool struct {
	// contains filtered or unexported fields
}

AtomBool Atomic Bool

func (*AtomBool) Get

func (atomBoolSelf *AtomBool) Get() bool

Get Get the bool atomically

func (*AtomBool) Set

func (atomBoolSelf *AtomBool) Set(value bool)

Set Set the bool atomically

type BufferedChannelQueue added in v2.2.0

type BufferedChannelQueue[T any] struct {
	// contains filtered or unexported fields
}

BufferedChannelQueue BlockingQueue with ChannelQueue & scalable pool, inspired by Collection utils

func NewBufferedChannelQueue added in v2.2.0

func NewBufferedChannelQueue[T any](channelCapacity int, bufferSizeMaximum int, nodeHookPoolSize int) *BufferedChannelQueue[T]

NewBufferedChannelQueue New BufferedChannelQueue instance from a Queue[T]

func (*BufferedChannelQueue[T]) Close added in v2.2.0

func (q *BufferedChannelQueue[T]) Close()

Close Close the BufferedChannelQueue

func (*BufferedChannelQueue[T]) Count added in v2.2.7

func (q *BufferedChannelQueue[T]) Count() int

Count Count items

func (*BufferedChannelQueue[T]) GetBufferSizeMaximum added in v2.2.5

func (q *BufferedChannelQueue[T]) GetBufferSizeMaximum() int

GetBufferSizeMaximum Get MaximumBufferSize(maximum number of buffered items outside the ChannelQueue)

func (*BufferedChannelQueue[T]) GetChannel added in v2.2.7

func (q *BufferedChannelQueue[T]) GetChannel() chan T

GetChannel Get Channel(for Selecting channels usages)

func (*BufferedChannelQueue[T]) GetFreeNodeHookPoolIntervalDuration added in v2.2.5

func (q *BufferedChannelQueue[T]) GetFreeNodeHookPoolIntervalDuration() time.Duration

GetFreeNodeHookPoolIntervalDuration Get freeNodeHookPoolIntervalDuration(the interval to clear buffering node hooks down to nodeHookPoolSize)

func (*BufferedChannelQueue[T]) GetLoadFromPoolDuration added in v2.2.5

func (q *BufferedChannelQueue[T]) GetLoadFromPoolDuration() time.Duration

GetLoadFromPoolDuration Get loadFromPoolDuration(the interval to take buffered items into the ChannelQueue)

func (*BufferedChannelQueue[T]) GetNodeHookPoolSize added in v2.2.5

func (q *BufferedChannelQueue[T]) GetNodeHookPoolSize() int

GetNodeHookPoolSize Get nodeHookPoolSize(the buffering node hooks ideal size)

func (*BufferedChannelQueue[T]) IsClosed added in v2.2.5

func (q *BufferedChannelQueue[T]) IsClosed() bool

IsClosed Is the BufferedChannelQueue closed

func (*BufferedChannelQueue[T]) Offer added in v2.2.0

func (q *BufferedChannelQueue[T]) Offer(val T) error

Offer Offer the T val(non-blocking)

func (*BufferedChannelQueue[T]) Poll added in v2.2.0

func (q *BufferedChannelQueue[T]) Poll() (T, error)

Poll Poll the T val(non-blocking)

func (*BufferedChannelQueue[T]) Put added in v2.2.0

func (q *BufferedChannelQueue[T]) Put(val T) error

Put Put the T val(non-blocking)

func (*BufferedChannelQueue[T]) SetBufferSizeMaximum added in v2.2.0

func (q *BufferedChannelQueue[T]) SetBufferSizeMaximum(size int) *BufferedChannelQueue[T]

SetBufferSizeMaximum Set MaximumBufferSize(maximum number of buffered items outside the ChannelQueue)

func (*BufferedChannelQueue[T]) SetFreeNodeHookPoolIntervalDuration added in v2.2.0

func (q *BufferedChannelQueue[T]) SetFreeNodeHookPoolIntervalDuration(duration time.Duration) *BufferedChannelQueue[T]

SetFreeNodeHookPoolIntervalDuration Set freeNodeHookPoolIntervalDuration(the interval to clear buffering node hooks down to nodeHookPoolSize)

func (*BufferedChannelQueue[T]) SetLoadFromPoolDuration added in v2.2.0

func (q *BufferedChannelQueue[T]) SetLoadFromPoolDuration(duration time.Duration) *BufferedChannelQueue[T]

SetLoadFromPoolDuration Set loadFromPoolDuration(the interval to take buffered items into the ChannelQueue)

func (*BufferedChannelQueue[T]) SetNodeHookPoolSize added in v2.2.0

func (q *BufferedChannelQueue[T]) SetNodeHookPoolSize(size int) *BufferedChannelQueue[T]

SetNodeHookPoolSize Set nodeHookPoolSize(the buffering node hooks ideal size)

func (*BufferedChannelQueue[T]) Take added in v2.2.0

func (q *BufferedChannelQueue[T]) Take() (T, error)

Take Take the T val(blocking)

func (*BufferedChannelQueue[T]) TakeWithTimeout added in v2.2.0

func (q *BufferedChannelQueue[T]) TakeWithTimeout(timeout time.Duration) (T, error)

TakeWithTimeout Take the T val(blocking), with timeout

type ChannelQueue added in v2.2.0

type ChannelQueue[T any] chan T

ChannelQueue ChannelQueue inspired by Collection utils

func NewChannelQueue added in v2.2.0

func NewChannelQueue[T any](capacity int) ChannelQueue[T]

NewChannelQueue New ChannelQueue instance with capacity

func (ChannelQueue[T]) Offer added in v2.2.0

func (q ChannelQueue[T]) Offer(val T) error

Offer Offer the T val(non-blocking)

func (ChannelQueue[T]) Poll added in v2.2.0

func (q ChannelQueue[T]) Poll() (T, error)

Poll Poll the T val(non-blocking)

func (ChannelQueue[T]) Put added in v2.2.0

func (q ChannelQueue[T]) Put(val T) error

Put Put the T val(blocking)

func (ChannelQueue[T]) PutWithTimeout added in v2.2.0

func (q ChannelQueue[T]) PutWithTimeout(val T, timeout time.Duration) error

PutWithTimeout Put the T val(blocking), with timeout

func (ChannelQueue[T]) Take added in v2.2.0

func (q ChannelQueue[T]) Take() (T, error)

Take Take the T val(blocking)

func (ChannelQueue[T]) TakeWithTimeout added in v2.2.0

func (q ChannelQueue[T]) TakeWithTimeout(timeout time.Duration) (T, error)

TakeWithTimeout Take the T val(blocking), with timeout

type CompData

type CompData struct {
	// contains filtered or unexported fields
}

CompData Composite Data with values & its CompType(SumType)

func NewCompData

func NewCompData(compType CompType, value ...interface{}) *CompData

NewCompData New SumType Data by its type and composite values

type CompType

type CompType interface {
	Matches(value ...interface{}) bool
}

CompType Abstract SumType concept interface

func DefProduct

func DefProduct(kinds ...reflect.Kind) CompType

DefProduct Define the ProductType of a SumType

func DefSum

func DefSum(compTypes ...CompType) CompType

DefSum Define the SumType by CompType list

type CompTypePatternDef

type CompTypePatternDef struct {
	// contains filtered or unexported fields
}

CompTypePatternDef Pattern which matching when the SumType matches

func (CompTypePatternDef) Apply

func (patternSelf CompTypePatternDef) Apply(value interface{}) interface{}

Apply Evaluate the result by its given effect function

func (CompTypePatternDef) Matches

func (patternSelf CompTypePatternDef) Matches(value interface{}) bool

Matches Match the given value by the pattern

type Comparable

type Comparable[T any] interface {
	CompareTo(T) int
}

Comparable Comparable interface able to be compared

type ComparableOrdered

type ComparableOrdered[T Ordered] struct {
	Val T
}

ComparableOrdered A Ordered Comparable for Comparator

func NewComparableOrdered

func NewComparableOrdered[T Ordered](val T) ComparableOrdered[T]

NewComparableOrdered Generate a Ordered Comparable for Comparator

func (ComparableOrdered[T]) CompareTo

func (obj ComparableOrdered[T]) CompareTo(input interface{}) int

CompareTo Compare with an another object

type ComparableString

type ComparableString struct {
	Val string
}

ComparableString A String Comparable for Comparator

func NewComparableString

func NewComparableString(val string) ComparableString

NewComparableString Generate a String Comparable for Comparator

func (ComparableString) CompareTo

func (obj ComparableString) CompareTo(input interface{}) int

CompareTo Compare with an another object

type Comparator

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

Comparator Comparator Functor

type ConcurrentQueue added in v2.2.0

type ConcurrentQueue[T any] struct {
	// contains filtered or unexported fields
}

ConcurrentQueue ConcurrentQueue inspired by Collection utils

func NewConcurrentQueue added in v2.2.0

func NewConcurrentQueue[T any](queue Queue[T]) *ConcurrentQueue[T]

NewConcurrentQueue New ConcurrentQueue instance from a Queue[T]

func (*ConcurrentQueue[T]) Offer added in v2.2.0

func (q *ConcurrentQueue[T]) Offer(val T) error

Offer Offer the T val(non-blocking)

func (*ConcurrentQueue[T]) Poll added in v2.2.0

func (q *ConcurrentQueue[T]) Poll() (T, error)

Poll Poll the T val(non-blocking)

func (*ConcurrentQueue[T]) Put added in v2.2.0

func (q *ConcurrentQueue[T]) Put(val T) error

Put Put the T val(probably blocking)

func (*ConcurrentQueue[T]) Take added in v2.2.0

func (q *ConcurrentQueue[T]) Take() (T, error)

Take Take the T val(probably blocking)

type ConcurrentStack added in v2.2.3

type ConcurrentStack[T any] struct {
	// contains filtered or unexported fields
}

ConcurrentStack ConcurrentStack inspired by Collection utils

func NewConcurrentStack added in v2.2.3

func NewConcurrentStack[T any](stack Stack[T]) *ConcurrentStack[T]

NewConcurrentStack New ConcurrentStack instance from a Stack[T]

func (*ConcurrentStack[T]) Pop added in v2.2.3

func (q *ConcurrentStack[T]) Pop() (T, error)

Take Take the T val(probably blocking)

func (*ConcurrentStack[T]) Push added in v2.2.3

func (q *ConcurrentStack[T]) Push(val T) error

Put Put the T val(probably blocking)

type CorDef

type CorDef[T any] struct {
	// contains filtered or unexported fields
}

CorDef Cor Coroutine inspired by Python/Ecmascript/Lua

var Cor CorDef[interface{}]

Cor Cor utils instance

func CorNewGenerics

func CorNewGenerics[T any](effect func()) *CorDef[T]

New New a Cor instance

func (*CorDef[T]) DoNotation

func (corSelf *CorDef[T]) DoNotation(effect func(*CorDef[T]) T) T

DoNotation Do Notation by function (inspired by Haskell one)

func (*CorDef[T]) IsDone

func (corSelf *CorDef[T]) IsDone() bool

IsDone Is the Cor done

func (*CorDef[T]) IsStarted

func (corSelf *CorDef[T]) IsStarted() bool

IsStarted Is the Cor started

func (*CorDef[T]) New

func (corSelf *CorDef[T]) New(effect func()) *CorDef[interface{}]

New New a Cor instance

func (*CorDef[T]) NewAndStart

func (corSelf *CorDef[T]) NewAndStart(effect func()) *CorDef[T]

NewAndStart New a Cor instance and start it immediately

func (*CorDef[T]) Start

func (corSelf *CorDef[T]) Start()

Start Start the Cor

func (*CorDef[T]) StartWithVal

func (corSelf *CorDef[T]) StartWithVal(in T)

StartWithVal Start the Cor with an initial value

func (*CorDef[T]) YieldFrom

func (corSelf *CorDef[T]) YieldFrom(target *CorDef[T], in T) T

YieldFrom Yield from a given Cor

func (*CorDef[T]) YieldFromIO

func (corSelf *CorDef[T]) YieldFromIO(target *MonadIODef[T]) T

YieldFromIO Yield from a given MonadIO

func (*CorDef[T]) YieldRef

func (corSelf *CorDef[T]) YieldRef(out T) T

YieldRef Yield a value

type CorOp

type CorOp[T any] struct {
	// contains filtered or unexported fields
}

CorOp Cor Yield Operation/Delegation/Callback

type CurryDef

type CurryDef[T any, R any] struct {
	// contains filtered or unexported fields
}

CurryDef Curry inspired by Currying in Java ways

func CurryNew

func CurryNew(fn func(c *CurryDef[interface{}, interface{}], args ...interface{}) interface{}) *CurryDef[interface{}, interface{}]

CurryNew New Curry instance by function

func CurryNewGenerics

func CurryNewGenerics[T any, R any](fn func(c *CurryDef[T, R], args ...T) R) *CurryDef[T, R]

CurryNewGenerics New Curry instance by function

func (*CurryDef[T, R]) Call

func (currySelf *CurryDef[T, R]) Call(args ...T) *CurryDef[T, R]

Call Call the currying function by partial or all args

func (*CurryDef[T, R]) IsDone

func (currySelf *CurryDef[T, R]) IsDone() bool

IsDone Is the currying done

func (*CurryDef[T, R]) MarkDone

func (currySelf *CurryDef[T, R]) MarkDone()

MarkDone Mark the currying is done(let others know it)

func (*CurryDef[T, R]) Result

func (currySelf *CurryDef[T, R]) Result() R

Result Get the result value of currying

type DoublyListItem added in v2.2.0

type DoublyListItem[T any] struct {
	Next *DoublyListItem[T]
	Prev *DoublyListItem[T]

	Val *T
}

DoublyListItem DoublyListItem inspired by Collection utils

func (*DoublyListItem[T]) AddFirst added in v2.2.0

func (listItem *DoublyListItem[T]) AddFirst(input *DoublyListItem[T]) *DoublyListItem[T]

AddFirst Add the input item to the first position

func (*DoublyListItem[T]) AddLast added in v2.2.0

func (listItem *DoublyListItem[T]) AddLast(input *DoublyListItem[T]) *DoublyListItem[T]

AddLast Add the input item to the last

func (*DoublyListItem[T]) Count added in v2.2.0

func (listItem *DoublyListItem[T]) Count() int

Count Count items

func (*DoublyListItem[T]) First added in v2.2.0

func (listItem *DoublyListItem[T]) First() *DoublyListItem[T]

First Get the First one

func (*DoublyListItem[T]) Last added in v2.2.0

func (listItem *DoublyListItem[T]) Last() *DoublyListItem[T]

Last Get the Last one

type EqualPatternDef

type EqualPatternDef struct {
	// contains filtered or unexported fields
}

EqualPatternDef Pattern which matching when the given object is equal to predefined one

func (EqualPatternDef) Apply

func (patternSelf EqualPatternDef) Apply(value interface{}) interface{}

Apply Evaluate the result by its given effect function

func (EqualPatternDef) Matches

func (patternSelf EqualPatternDef) Matches(value interface{}) bool

Matches Match the given value by the pattern

type FieldSortDescriptor

type FieldSortDescriptor[T any] struct {
	SimpleSortDescriptor[T]
	// contains filtered or unexported fields
}

FieldSortDescriptor FieldSortDescriptor implemented by Reflection(by FieldName)

func NewFieldSortDescriptor

func NewFieldSortDescriptor[T any](fieldName string, ascending bool) FieldSortDescriptor[T]

NewFieldSortDescriptor Generate a new FieldSortDescriptor by FieldName & ascending(true)/descending(false)

func (FieldSortDescriptor[T]) GetFieldName

func (descriptor FieldSortDescriptor[T]) GetFieldName() string

GetFieldName Get the fieldName to sort

func (FieldSortDescriptor[T]) SetFieldName

func (descriptor FieldSortDescriptor[T]) SetFieldName(val string)

SetFieldName Set the fieldName to sort

func (FieldSortDescriptor[T]) TransformedBy

func (descriptor FieldSortDescriptor[T]) TransformedBy() TransformerFunctor[T, Comparable[interface{}]]

TransformedBy Get the TransformerFunctor of this SortDescriptor

type HandlerDef

type HandlerDef struct {
	// contains filtered or unexported fields
}

HandlerDef Handler inspired by Android/WebWorker

var Handler HandlerDef

Handler Handler utils instance

func (*HandlerDef) Close

func (handlerSelf *HandlerDef) Close()

Close Close the Handler

func (*HandlerDef) GetDefault

func (handlerSelf *HandlerDef) GetDefault() *HandlerDef

GetDefault Get Default Handler

func (*HandlerDef) New

func (handlerSelf *HandlerDef) New() *HandlerDef

New New Handler instance

func (*HandlerDef) NewByCh

func (handlerSelf *HandlerDef) NewByCh(ioCh chan func()) *HandlerDef

NewByCh New Handler by its Channel

func (*HandlerDef) Post

func (handlerSelf *HandlerDef) Post(fn func())

Post Post a function to execute on the Handler

type KindPatternDef

type KindPatternDef struct {
	// contains filtered or unexported fields
}

KindPatternDef Pattern which matching when the kind matches

func (KindPatternDef) Apply

func (patternSelf KindPatternDef) Apply(value interface{}) interface{}

Apply Evaluate the result by its given effect function

func (KindPatternDef) Matches

func (patternSelf KindPatternDef) Matches(value interface{}) bool

Matches Match the given value by the pattern

type LinkedListItem added in v2.2.0

type LinkedListItem[T any] struct {
	Next *LinkedListItem[T]

	Val *T
}

LinkedListItem LinkedListItem inspired by Collection utils

func (*LinkedListItem[T]) AddLast added in v2.2.0

func (listItem *LinkedListItem[T]) AddLast(input *LinkedListItem[T]) *LinkedListItem[T]

AddLast Add the input item to the last

func (*LinkedListItem[T]) Count added in v2.2.0

func (listItem *LinkedListItem[T]) Count() int

Count Count items

func (*LinkedListItem[T]) Last added in v2.2.0

func (listItem *LinkedListItem[T]) Last() *LinkedListItem[T]

Last Get the Last one

type LinkedListQueue added in v2.2.0

type LinkedListQueue[T any] struct {
	// contains filtered or unexported fields
}

LinkedListQueue LinkedListQueue inspired by Collection utils

func NewLinkedListQueue added in v2.2.0

func NewLinkedListQueue[T any]() *LinkedListQueue[T]

NewLinkedListQueue New LinkedListQueue instance

func (*LinkedListQueue[T]) Clear added in v2.2.0

func (q *LinkedListQueue[T]) Clear()

CLear Clear all data

func (*LinkedListQueue[T]) ClearNodePool added in v2.2.0

func (q *LinkedListQueue[T]) ClearNodePool()

ClearNodePool Clear cached LinkedListItem nodes in nodePool

func (*LinkedListQueue[T]) Count added in v2.2.0

func (q *LinkedListQueue[T]) Count() int

Count Count Items

func (*LinkedListQueue[T]) KeepNodePoolCount added in v2.2.0

func (q *LinkedListQueue[T]) KeepNodePoolCount(n int)

KeepNodePoolCount Decrease/Increase LinkedListItem nodes to n items

func (*LinkedListQueue[T]) Offer added in v2.2.0

func (q *LinkedListQueue[T]) Offer(val T) error

Offer Offer the T val to the last position(non-blocking)

func (*LinkedListQueue[T]) Peek added in v2.2.0

func (q *LinkedListQueue[T]) Peek() (T, error)

Peek Peek the T val from the first position without removing it (non-blocking)

func (*LinkedListQueue[T]) Poll added in v2.2.0

func (q *LinkedListQueue[T]) Poll() (T, error)

Poll Poll the T val from the first position(non-blocking)

func (*LinkedListQueue[T]) Pop added in v2.2.0

func (q *LinkedListQueue[T]) Pop() (T, error)

Pop Pop the data from the last position(non-blocking)

func (*LinkedListQueue[T]) Push added in v2.2.0

func (q *LinkedListQueue[T]) Push(val T) error

Push Push the data to the last position(non-blocking)

func (*LinkedListQueue[T]) Put added in v2.2.0

func (q *LinkedListQueue[T]) Put(val T) error

Put Put the T val to the last position(no-blocking)

func (*LinkedListQueue[T]) Shift added in v2.2.0

func (q *LinkedListQueue[T]) Shift() (T, error)

Shift Shift the T val from the first position (non-blocking)

func (*LinkedListQueue[T]) Take added in v2.2.0

func (q *LinkedListQueue[T]) Take() (T, error)

Take Take the T val from the first position(no-blocking)

func (*LinkedListQueue[T]) Unshift added in v2.2.0

func (q *LinkedListQueue[T]) Unshift(val T) error

Unshift Unshift the T val to the first position(non-blocking)

type MapSetDef

type MapSetDef[T comparable, R comparable] map[T]R

MapSetDef Set inspired by Collection utils

func SetFrom

func SetFrom[T comparable, R comparable](list ...T) *MapSetDef[T, R]

SetFrom New Set instance from a T array

func SetFromArray

func SetFromArray[T comparable, R comparable](list []T) *MapSetDef[T, R]

SetFromArray New Set instance from a T array

func SetFromMap

func SetFromMap[T comparable, R comparable](theMap map[T]R) *MapSetDef[T, R]

SetFromMap New Set instance from a map[T]R

func (*MapSetDef[T, R]) Add

func (mapSetSelf *MapSetDef[T, R]) Add(input ...T) SetDef[T, R]

Add Add items into the Set

func (*MapSetDef[T, R]) AsMap

func (mapSetSelf *MapSetDef[T, R]) AsMap() map[T]R

AsMap Make Set an object typed as map[T] R

func (*MapSetDef[T, R]) AsMapSet

func (mapSetSelf *MapSetDef[T, R]) AsMapSet() *MapSetDef[T, R]

AsMapSet Make Set an object typed as *MapSetDef[T, R]

func (*MapSetDef[T, R]) Clone

func (mapSetSelf *MapSetDef[T, R]) Clone() SetDef[T, R]

Clone Clone this Set

func (*MapSetDef[T, R]) ContainsKey

func (mapSetSelf *MapSetDef[T, R]) ContainsKey(input T) bool

ContainsKey Check the key exists or not in the Set

func (*MapSetDef[T, R]) ContainsValue

func (mapSetSelf *MapSetDef[T, R]) ContainsValue(input R) bool

ContainsValue Check the value exists or not in the Set

func (*MapSetDef[T, R]) Get

func (mapSetSelf *MapSetDef[T, R]) Get(key T) R

Get Get items from the Set

func (*MapSetDef[T, R]) Intersection

func (mapSetSelf *MapSetDef[T, R]) Intersection(input SetDef[T, R]) SetDef[T, R]

Intersection Get the Intersection with this Set and an another Set

func (*MapSetDef[T, R]) IsSubsetByKey

func (mapSetSelf *MapSetDef[T, R]) IsSubsetByKey(input SetDef[T, R]) bool

IsSubsetByKey returns true or false by checking if set1 is a subset of set2

func (*MapSetDef[T, R]) IsSupersetByKey

func (mapSetSelf *MapSetDef[T, R]) IsSupersetByKey(input SetDef[T, R]) bool

IsSupersetByKey returns true or false by checking if set1 is a superset of set2

func (*MapSetDef[T, R]) Keys

func (mapSetSelf *MapSetDef[T, R]) Keys() []T

Keys Convert Set to slice

func (*MapSetDef[T, R]) MapKey

func (mapSetSelf *MapSetDef[T, R]) MapKey(fn TransformerFunctor[T, T]) SetDef[T, R]

MapKey Map all keys of Set by function

func (*MapSetDef[T, R]) MapValue

func (mapSetSelf *MapSetDef[T, R]) MapValue(fn TransformerFunctor[R, R]) SetDef[T, R]

MapValue Map all values of Set by function

func (*MapSetDef[T, R]) Minus

func (mapSetSelf *MapSetDef[T, R]) Minus(input SetDef[T, R]) SetDef[T, R]

Minus Get all of this Set but not in the given Set

func (*MapSetDef[T, R]) RemoveKeys

func (mapSetSelf *MapSetDef[T, R]) RemoveKeys(input ...T) SetDef[T, R]

RemoveKeys Remove keys from the Set

func (*MapSetDef[T, R]) RemoveValues

func (mapSetSelf *MapSetDef[T, R]) RemoveValues(input ...R) SetDef[T, R]

RemoveValues Remove values from the Set

func (*MapSetDef[T, R]) Set

func (mapSetSelf *MapSetDef[T, R]) Set(key T, value R)

Set Set items to the Set

func (*MapSetDef[T, R]) Size

func (mapSetSelf *MapSetDef[T, R]) Size() int

Size Get size

func (*MapSetDef[T, R]) Union

func (mapSetSelf *MapSetDef[T, R]) Union(input SetDef[T, R]) SetDef[T, R]

Union Union an another Set object

func (*MapSetDef[T, R]) Values

func (mapSetSelf *MapSetDef[T, R]) Values() []R

Values Convert Set to slice

type MaybeDef

type MaybeDef[T any] interface {
	Just(in interface{}) MaybeDef[interface{}]
	Or(or T) T
	Clone() MaybeDef[T]
	FlatMap(fn func(T) MaybeDef[T]) MaybeDef[T]
	ToString() string
	ToPtr() *T
	ToMaybe() MaybeDef[T]
	ToFloat64() (float64, error)
	ToFloat32() (float32, error)
	ToInt() (int, error)
	ToInt32() (int32, error)
	ToInt64() (int64, error)
	ToBool() (bool, error)
	Let(fn func())
	Unwrap() T
	UnwrapInterface() interface{}
	IsPresent() bool
	IsNil() bool
	IsValid() bool
	IsPtr() bool
	Type() reflect.Type
	Kind() reflect.Kind
	IsType(t reflect.Type) bool
	IsKind(t reflect.Kind) bool
}

MaybeDef Maybe inspired by Rx/Optional/Guava/Haskell

func CloneTo

func CloneTo[T any](maybeSelf MaybeDef[T], dest T) MaybeDef[T]

CloneTo Clone the Ptr target to an another Ptr target

func JustGenerics

func JustGenerics[T any](in T) MaybeDef[T]

JustGenerics New Maybe by a given value

type MonadIODef

type MonadIODef[T any] struct {
	// contains filtered or unexported fields
}

MonadIODef MonadIO inspired by Rx/Observable

var MonadIO MonadIODef[interface{}]

MonadIO MonadIO utils instance

func MonadIOJustGenerics

func MonadIOJustGenerics[T any](in T) *MonadIODef[T]

MonadIOJustGenerics New MonadIO by a given value

func MonadIONewGenerics

func MonadIONewGenerics[T any](effect func() T) *MonadIODef[T]

MonadIONewGenerics New MonadIO by effect function

func (*MonadIODef[T]) Eval

func (monadIOSelf *MonadIODef[T]) Eval() T

Eval Eval the value right now(sync)

func (*MonadIODef[T]) FlatMap

func (monadIOSelf *MonadIODef[T]) FlatMap(fn func(T) *MonadIODef[T]) *MonadIODef[T]

FlatMap FlatMap the MonadIO by function

func (MonadIODef[T]) Just

func (monadIOSelf MonadIODef[T]) Just(in interface{}) *MonadIODef[interface{}]

Just New MonadIO by a given value

func (*MonadIODef[T]) New

func (monadIOSelf *MonadIODef[T]) New(effect func() T) *MonadIODef[T]

New New MonadIO by effect function

func (*MonadIODef[T]) ObserveOn

func (monadIOSelf *MonadIODef[T]) ObserveOn(h *HandlerDef) *MonadIODef[T]

ObserveOn Observe the MonadIO on the specific Handler

func (*MonadIODef[T]) Subscribe

func (monadIOSelf *MonadIODef[T]) Subscribe(s Subscription[T]) *Subscription[T]

Subscribe Subscribe the MonadIO by Subscription

func (*MonadIODef[T]) SubscribeOn

func (monadIOSelf *MonadIODef[T]) SubscribeOn(h *HandlerDef) *MonadIODef[T]

SubscribeOn Subscribe the MonadIO on the specific Handler

type NilTypeDef

type NilTypeDef struct{}

NilTypeDef NilType implemented by Nil determinations

var NilType NilTypeDef

NilType NilType CompType instance

func (NilTypeDef) Matches

func (typeSelf NilTypeDef) Matches(value ...interface{}) bool

Matches Check does it match nil

type Numeric

type Numeric interface {
	int | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64
}

Numeric Define Numeric types for Generics

type Ordered

type Ordered interface {
	int | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | uintptr | string | float32 | float64
}

Ordered Define Ordered types for Generics

type OtherwisePatternDef

type OtherwisePatternDef struct {
	// contains filtered or unexported fields
}

OtherwisePatternDef Pattern which matching when the others didn't match(finally)

func (OtherwisePatternDef) Apply

func (patternSelf OtherwisePatternDef) Apply(value interface{}) interface{}

Apply Evaluate the result by its given effect function

func (OtherwisePatternDef) Matches

func (patternSelf OtherwisePatternDef) Matches(value interface{}) bool

Matches Match the given value by the pattern

type PMapOption

type PMapOption struct {
	FixedPool   int // number of goroutines
	RandomOrder bool
}

PMapOption Options for PMap usages

type Pattern

type Pattern interface {
	Matches(value interface{}) bool
	Apply(interface{}) interface{}
}

Pattern Pattern general interface

func InCaseOfEqual

func InCaseOfEqual(value interface{}, effect fnObj) Pattern

InCaseOfEqual In case of its value is equal to the given one

func InCaseOfKind

func InCaseOfKind(kind reflect.Kind, effect fnObj) Pattern

InCaseOfKind In case of its Kind matches the given one

func InCaseOfRegex

func InCaseOfRegex(pattern string, effect fnObj) Pattern

InCaseOfRegex In case of the given regex rule matches its value

func InCaseOfSumType

func InCaseOfSumType(compType CompType, effect fnObj) Pattern

InCaseOfSumType In case of its SumType matches the given one

func Otherwise

func Otherwise(effect fnObj) Pattern

Otherwise In case of the other patterns didn't match it

type PatternMatching

type PatternMatching struct {
	// contains filtered or unexported fields
}

PatternMatching PatternMatching contains Pattern list

func DefPattern

func DefPattern(patterns ...Pattern) PatternMatching

DefPattern Define the PatternMatching by Pattern list

func (PatternMatching) MatchFor

func (patternMatchingSelf PatternMatching) MatchFor(inValue interface{}) interface{}

MatchFor Check does the given value match anyone of the Pattern list of PatternMatching

type Predicate

type Predicate[T any] func(T) bool

Predicate Predicate Functor

type PredicateErr

type PredicateErr[T any] func(T, int) (bool, error)

PredicateErr Predicate Functor

type ProductType

type ProductType struct {
	// contains filtered or unexported fields
}

ProductType ProductType with a Kind list

func (ProductType) Matches

func (typeSelf ProductType) Matches(value ...interface{}) bool

Matches Check does it match the ProductType

type PublisherDef

type PublisherDef[T any] struct {
	// contains filtered or unexported fields
}

PublisherDef Publisher inspired by Rx/NotificationCenter/PubSub

var Publisher PublisherDef[interface{}]

Publisher Publisher utils instance

func PublisherNewGenerics

func PublisherNewGenerics[T any]() *PublisherDef[T]

PublisherNewGenerics New a Publisher

func (*PublisherDef[T]) Map

func (publisherSelf *PublisherDef[T]) Map(fn func(T) T) *PublisherDef[T]

Map Map the Publisher in order to make a broadcasting chain

func (*PublisherDef[T]) New

func (publisherSelf *PublisherDef[T]) New() *PublisherDef[interface{}]

New New a Publisher

func (*PublisherDef[T]) Publish

func (publisherSelf *PublisherDef[T]) Publish(result T)

Publish Publish a value to its subscribers or next chains

func (*PublisherDef[T]) Subscribe

func (publisherSelf *PublisherDef[T]) Subscribe(sub Subscription[T]) *Subscription[T]

Subscribe Subscribe the Publisher by Subscription[T]

func (*PublisherDef[T]) SubscribeOn

func (publisherSelf *PublisherDef[T]) SubscribeOn(h *HandlerDef) *PublisherDef[T]

SubscribeOn Subscribe the Publisher on the specific Handler

func (*PublisherDef[T]) Unsubscribe

func (publisherSelf *PublisherDef[T]) Unsubscribe(s *Subscription[T])

Unsubscribe Unsubscribe the publisher by the Subscription[T]

type Queue added in v2.2.0

type Queue[T any] interface {
	Put(val T) error
	Take() (T, error)
	Offer(val T) error
	Poll() (T, error)
}

Queue Queue inspired by Collection utils

type ReducerFunctor

type ReducerFunctor[T any, R any] func(R, T) R

ReducerFunctor Functor for Reduce

type RegexPatternDef

type RegexPatternDef struct {
	// contains filtered or unexported fields
}

RegexPatternDef Pattern which matching when the regex rule matches the given string

func (RegexPatternDef) Apply

func (patternSelf RegexPatternDef) Apply(value interface{}) interface{}

Apply Evaluate the result by its given effect function

func (RegexPatternDef) Matches

func (patternSelf RegexPatternDef) Matches(value interface{}) bool

Matches Match the given value by the pattern

type SetDef

type SetDef[T comparable, R comparable] interface {
	MapKey(fn TransformerFunctor[T, T]) SetDef[T, R]
	MapValue(fn TransformerFunctor[R, R]) SetDef[T, R]
	ContainsKey(input T) bool
	ContainsValue(input R) bool
	IsSubsetByKey(input SetDef[T, R]) bool
	IsSupersetByKey(input SetDef[T, R]) bool
	Add(input ...T) SetDef[T, R]
	RemoveKeys(input ...T) SetDef[T, R]
	RemoveValues(input ...R) SetDef[T, R]
	Get(key T) R
	Set(key T, value R)
	Clone() SetDef[T, R]
	Union(input SetDef[T, R]) SetDef[T, R]
	Intersection(input SetDef[T, R]) SetDef[T, R]
	Minus(input SetDef[T, R]) SetDef[T, R]
	Size() int
	Keys() []T
	Values() []R
	AsMap() map[T]R
	AsMapSet() *MapSetDef[T, R]
}

SetDef Set inspired by Collection utils

type SetForInterfaceDef

type SetForInterfaceDef map[interface{}]interface{}

SetForInterfaceDef Set inspired by Collection utils

Set Set utils instance

func SetForInterfaceFrom

func SetForInterfaceFrom(list ...interface{}) *SetForInterfaceDef

SetForInterfaceFrom New Set instance from a interface{} array

func SetForInterfaceFromArray

func SetForInterfaceFromArray(list []interface{}) *SetForInterfaceDef

SetForInterfaceFromArray New Set instance from a interface{} array

func SetForInterfaceFromMap

func SetForInterfaceFromMap(theMap map[interface{}]interface{}) *SetForInterfaceDef

SetForInterfaceFromMap New Set instance from a map[interface{}]R

func (*SetForInterfaceDef) Add

func (setSelf *SetForInterfaceDef) Add(input ...interface{}) *SetForInterfaceDef

Add Add items into the Set

func (*SetForInterfaceDef) Clone

func (setSelf *SetForInterfaceDef) Clone() *SetForInterfaceDef

Clone Clone this Set

func (*SetForInterfaceDef) ContainsKey

func (setSelf *SetForInterfaceDef) ContainsKey(input interface{}) bool

ContainsKey Check the key exists or not in the Set

func (*SetForInterfaceDef) ContainsValue

func (setSelf *SetForInterfaceDef) ContainsValue(input interface{}) bool

ContainsValue Check the value exists or not in the Set

func (*SetForInterfaceDef) Get

func (setSelf *SetForInterfaceDef) Get(key interface{}) interface{}

Get Get items from the Set

func (*SetForInterfaceDef) Intersection

func (setSelf *SetForInterfaceDef) Intersection(input *SetForInterfaceDef) *SetForInterfaceDef

Intersection Get the Intersection with this Set and an another Set

func (*SetForInterfaceDef) IsSubsetByKey

func (setSelf *SetForInterfaceDef) IsSubsetByKey(input *SetForInterfaceDef) bool

IsSubsetByKey returns true or false by checking if set1 is a subset of set2

func (*SetForInterfaceDef) IsSupersetByKey

func (setSelf *SetForInterfaceDef) IsSupersetByKey(input *SetForInterfaceDef) bool

IsSupersetByKey returns true or false by checking if set1 is a superset of set2

func (*SetForInterfaceDef) Keys

func (setSelf *SetForInterfaceDef) Keys() []interface{}

Keys Convert Set to slice

func (*SetForInterfaceDef) MapKey

func (setSelf *SetForInterfaceDef) MapKey(fn TransformerFunctor[interface{}, interface{}]) *SetForInterfaceDef

MapKey Map all keys of Set by function

func (*SetForInterfaceDef) MapValue

func (setSelf *SetForInterfaceDef) MapValue(fn TransformerFunctor[interface{}, interface{}]) *SetForInterfaceDef

MapValue Map all values of Set by function

func (*SetForInterfaceDef) Minus

Minus Get all of this Set but not in the given Set

func (*SetForInterfaceDef) RemoveKeys

func (setSelf *SetForInterfaceDef) RemoveKeys(input ...interface{}) *SetForInterfaceDef

RemoveKeys Remove keys from the Set

func (*SetForInterfaceDef) RemoveValues

func (setSelf *SetForInterfaceDef) RemoveValues(input ...interface{}) *SetForInterfaceDef

RemoveValues Remove values from the Set

func (*SetForInterfaceDef) Set

func (setSelf *SetForInterfaceDef) Set(key interface{}, value interface{})

Set Set items to the Set

func (*SetForInterfaceDef) Size

func (setSelf *SetForInterfaceDef) Size() int

Size Get size

func (*SetForInterfaceDef) Union

Union Union an another Set object

func (*SetForInterfaceDef) Values

func (setSelf *SetForInterfaceDef) Values() []interface{}

Values Convert Set to slice

type SimpleSortDescriptor

type SimpleSortDescriptor[T any] struct {
	// contains filtered or unexported fields
}

SimpleSortDescriptor SimpleSortDescriptor implemented by TransformerFunctor

func NewSimpleSortDescriptor

func NewSimpleSortDescriptor[T any](transformFn TransformerFunctor[T, Comparable[interface{}]], ascending bool) SimpleSortDescriptor[T]

NewSimpleSortDescriptor Generate a new SimpleSortDescriptor by TransformerFunctor & ascending(true)/descending(false)

func (SimpleSortDescriptor[T]) IsAscending

func (descriptor SimpleSortDescriptor[T]) IsAscending() bool

IsAscending Check is this SortDescriptor sorting by ascending

func (SimpleSortDescriptor[T]) SetAscending

func (descriptor SimpleSortDescriptor[T]) SetAscending(val bool)

SetAscending Set this SortDescriptor sorting by ascending(true) or descending(false)

func (SimpleSortDescriptor[T]) TransformedBy

func (descriptor SimpleSortDescriptor[T]) TransformedBy() TransformerFunctor[T, Comparable[interface{}]]

TransformedBy Get the TransformerFunctor of this SortDescriptor

type SortDescriptor

type SortDescriptor[T any] interface {
	Transformer[T, Comparable[any]]

	IsAscending() bool
	SetAscending(bool)
}

SortDescriptor Define a Transformer Pattern SortDescriptor

type SortDescriptorsBuilder

type SortDescriptorsBuilder[T any] []SortDescriptor[T]

SortDescriptorsBuilder SortDescriptorsBuilder for composing SortDescriptor list and sorting data

func NewSortDescriptorsBuilder

func NewSortDescriptorsBuilder[T any]() SortDescriptorsBuilder[T]

NewSortDescriptorsBuilder Generate a new SortDescriptorsBuilder

func (SortDescriptorsBuilder[T]) GetSortDescriptors

func (builder SortDescriptorsBuilder[T]) GetSortDescriptors() []SortDescriptor[T]

GetSortDescriptors Get sortDescriptors

func (SortDescriptorsBuilder[T]) Sort

func (builder SortDescriptorsBuilder[T]) Sort(input []T)

Sort Sort by sortDescriptors

func (SortDescriptorsBuilder[T]) ThenWith

func (builder SortDescriptorsBuilder[T]) ThenWith(input ...SortDescriptor[T]) SortDescriptorsBuilder[T]

ThenWith Append a SortDescriptor

func (SortDescriptorsBuilder[T]) ThenWithFieldName

func (builder SortDescriptorsBuilder[T]) ThenWithFieldName(fieldName string, ascending bool) SortDescriptorsBuilder[T]

ThenWithFieldName Use FieldName as a SortDescriptor

func (SortDescriptorsBuilder[T]) ThenWithTransformerFunctor

func (builder SortDescriptorsBuilder[T]) ThenWithTransformerFunctor(transformFn TransformerFunctor[T, Comparable[interface{}]], ascending bool) SortDescriptorsBuilder[T]

ThenWithTransformerFunctor Use TransformerFunctor as a SortDescriptor

func (SortDescriptorsBuilder[T]) ToSortedList

func (builder SortDescriptorsBuilder[T]) ToSortedList(input ...T) []T

ToSortedList Get the sorted result

type Stack added in v2.2.0

type Stack[T any] interface {
	Push(val T) error
	Pop() (T, error)
}

Stack Stack inspired by Collection utils

type StreamDef

type StreamDef[T comparable] []T

StreamDef Stream inspired by Collection utils

func StreamFrom

func StreamFrom[T comparable](list ...T) *StreamDef[T]

StreamFrom New Stream instance from a T array

func StreamFromArray

func StreamFromArray[T comparable](list []T) *StreamDef[T]

StreamFromArray New Stream instance from a T array

func (*StreamDef[T]) Append

func (streamSelf *StreamDef[T]) Append(item ...T) *StreamDef[T]

Append Append an item to Stream

func (*StreamDef[T]) Clone

func (streamSelf *StreamDef[T]) Clone() *StreamDef[T]

Clone Clone this Stream

func (*StreamDef[T]) Concat

func (streamSelf *StreamDef[T]) Concat(slices ...[]T) *StreamDef[T]

Concat Concat Stream by another slices

func (*StreamDef[T]) Contains

func (streamSelf *StreamDef[T]) Contains(input T) bool

Contains Check the item exists or not in the Stream

func (*StreamDef[T]) Distinct

func (streamSelf *StreamDef[T]) Distinct() *StreamDef[T]

Distinct Filter duplicated items and return a new Stream instance

func (*StreamDef[T]) Extend

func (streamSelf *StreamDef[T]) Extend(streams ...*StreamDef[T]) *StreamDef[T]

Extend Extend Stream by another Stream(s)

func (*StreamDef[T]) Filter

func (streamSelf *StreamDef[T]) Filter(fn func(T, int) bool) *StreamDef[T]

Filter Filter items of Stream by function

func (*StreamDef[T]) FilterNotNil

func (streamSelf *StreamDef[T]) FilterNotNil() *StreamDef[T]

FilterNotNil Filter not nil items and return a new Stream instance

func (*StreamDef[T]) Get

func (streamSelf *StreamDef[T]) Get(i int) T

Get Get an item of Stream by its index

func (*StreamDef[T]) Intersection

func (streamSelf *StreamDef[T]) Intersection(input *StreamDef[T]) *StreamDef[T]

Intersection Get the Intersection with this Stream and an another Stream

func (*StreamDef[T]) IsSubset

func (streamSelf *StreamDef[T]) IsSubset(input *StreamDef[T]) bool

IsSubset returns true or false by checking if stream1 is a subset of stream2

func (*StreamDef[T]) IsSuperset

func (streamSelf *StreamDef[T]) IsSuperset(input *StreamDef[T]) bool

IsSuperset returns true or false by checking if stream1 is a superset of stream2

func (*StreamDef[T]) Len

func (streamSelf *StreamDef[T]) Len() int

Len Get length of Stream

func (*StreamDef[T]) Map

func (streamSelf *StreamDef[T]) Map(fn func(T, int) T) *StreamDef[T]

Map Map all items of Stream by function

func (*StreamDef[T]) Minus

func (streamSelf *StreamDef[T]) Minus(input *StreamDef[T]) *StreamDef[T]

Minus Get all of this Stream but not in the given Stream

func (*StreamDef[T]) Reject

func (streamSelf *StreamDef[T]) Reject(fn func(T, int) bool) *StreamDef[T]

Reject Reject items of Stream by function

func (*StreamDef[T]) Remove

func (streamSelf *StreamDef[T]) Remove(index int) *StreamDef[T]

Remove Remove an item by its index

func (*StreamDef[T]) RemoveItem

func (streamSelf *StreamDef[T]) RemoveItem(input ...T) *StreamDef[T]

RemoveItem Remove items from the Stream

func (*StreamDef[T]) Reverse

func (streamSelf *StreamDef[T]) Reverse() *StreamDef[T]

Reverse Reverse Stream items

func (*StreamDef[T]) Sort

func (streamSelf *StreamDef[T]) Sort(fn Comparator[T]) *StreamDef[T]

Sort Sort Stream items by Comparator

func (*StreamDef[T]) SortByIndex

func (streamSelf *StreamDef[T]) SortByIndex(fn func(a, b int) bool) *StreamDef[T]

SortByIndex Sort Stream items by function(index, index) bool

func (*StreamDef[T]) ToArray

func (streamSelf *StreamDef[T]) ToArray() []T

ToArray Convert Stream to slice

type StreamForInterfaceDef

type StreamForInterfaceDef []interface{}

StreamForInterfaceDef Stream inspired by Collection utils

var StreamForInterface StreamForInterfaceDef

StreamForInterface Stream utils instance

func (*StreamForInterfaceDef) Append

func (streamSelf *StreamForInterfaceDef) Append(item ...interface{}) *StreamForInterfaceDef

Append Append an item to Stream

func (*StreamForInterfaceDef) Clone

func (streamSelf *StreamForInterfaceDef) Clone() *StreamForInterfaceDef

Clone Clone this Stream

func (*StreamForInterfaceDef) Concat

func (streamSelf *StreamForInterfaceDef) Concat(slices ...[]interface{}) *StreamForInterfaceDef

Concat Concat Stream by another slices

func (*StreamForInterfaceDef) Contains

func (streamSelf *StreamForInterfaceDef) Contains(input interface{}) bool

Contains Check the item exists or not in the Stream

func (*StreamForInterfaceDef) Distinct

func (streamSelf *StreamForInterfaceDef) Distinct() *StreamForInterfaceDef

Distinct Filter duplicated items and return a new Stream instance

func (*StreamForInterfaceDef) Extend

func (streamSelf *StreamForInterfaceDef) Extend(streams ...*StreamForInterfaceDef) *StreamForInterfaceDef

Extend Extend Stream by another Stream(s)

func (*StreamForInterfaceDef) Filter

func (streamSelf *StreamForInterfaceDef) Filter(fn func(interface{}, int) bool) *StreamForInterfaceDef

Filter Filter items of Stream by function

func (*StreamForInterfaceDef) FilterNotNil

func (streamSelf *StreamForInterfaceDef) FilterNotNil() *StreamForInterfaceDef

FilterNotNil Filter not nil items and return a new Stream instance

func (*StreamForInterfaceDef) From

func (streamSelf *StreamForInterfaceDef) From(list ...interface{}) *StreamForInterfaceDef

From New Stream instance from a interface{} array

func (*StreamForInterfaceDef) FromArray

func (streamSelf *StreamForInterfaceDef) FromArray(list []interface{}) *StreamForInterfaceDef

FromArray New Stream instance from an interface{} array

func (*StreamForInterfaceDef) FromArrayBool

func (streamSelf *StreamForInterfaceDef) FromArrayBool(old []bool) *StreamForInterfaceDef

FromArrayBool New Stream instance from a bool array

func (*StreamForInterfaceDef) FromArrayByte

func (streamSelf *StreamForInterfaceDef) FromArrayByte(old []byte) *StreamForInterfaceDef

FromArrayByte New Stream instance from an int8 array

func (*StreamForInterfaceDef) FromArrayFloat32

func (streamSelf *StreamForInterfaceDef) FromArrayFloat32(old []float32) *StreamForInterfaceDef

FromArrayFloat32 New Stream instance from a float32 array

func (*StreamForInterfaceDef) FromArrayFloat64

func (streamSelf *StreamForInterfaceDef) FromArrayFloat64(old []float64) *StreamForInterfaceDef

FromArrayFloat64 New Stream instance from a float64 array

func (*StreamForInterfaceDef) FromArrayInt

func (streamSelf *StreamForInterfaceDef) FromArrayInt(old []int) *StreamForInterfaceDef

FromArrayInt New Stream instance from an int array

func (*StreamForInterfaceDef) FromArrayInt16

func (streamSelf *StreamForInterfaceDef) FromArrayInt16(old []int16) *StreamForInterfaceDef

FromArrayInt16 New Stream instance from an int16 array

func (*StreamForInterfaceDef) FromArrayInt32

func (streamSelf *StreamForInterfaceDef) FromArrayInt32(old []int32) *StreamForInterfaceDef

FromArrayInt32 New Stream instance from an int32 array

func (*StreamForInterfaceDef) FromArrayInt64

func (streamSelf *StreamForInterfaceDef) FromArrayInt64(old []int64) *StreamForInterfaceDef

FromArrayInt64 New Stream instance from an int64 array

func (*StreamForInterfaceDef) FromArrayInt8

func (streamSelf *StreamForInterfaceDef) FromArrayInt8(old []int8) *StreamForInterfaceDef

FromArrayInt8 New Stream instance from an int8 array

func (*StreamForInterfaceDef) FromArrayMaybe

func (streamSelf *StreamForInterfaceDef) FromArrayMaybe(old []MaybeDef[interface{}]) *StreamForInterfaceDef

FromArrayMaybe FromArrayMaybe New Stream instance from a Maybe array

func (*StreamForInterfaceDef) FromArrayString

func (streamSelf *StreamForInterfaceDef) FromArrayString(old []string) *StreamForInterfaceDef

FromArrayString New Stream instance from a string array

func (*StreamForInterfaceDef) Get

func (streamSelf *StreamForInterfaceDef) Get(i int) interface{}

Get Get an item of Stream by its index

func (*StreamForInterfaceDef) Intersection

func (streamSelf *StreamForInterfaceDef) Intersection(input *StreamForInterfaceDef) *StreamForInterfaceDef

Intersection Get the Intersection with this Stream and an another Stream

func (*StreamForInterfaceDef) IsSubset

func (streamSelf *StreamForInterfaceDef) IsSubset(input *StreamForInterfaceDef) bool

IsSubset returns true or false by checking if stream1 is a subset of stream2

func (*StreamForInterfaceDef) IsSuperset

func (streamSelf *StreamForInterfaceDef) IsSuperset(input *StreamForInterfaceDef) bool

IsSuperset returns true or false by checking if stream1 is a superset of stream2

func (*StreamForInterfaceDef) Len

func (streamSelf *StreamForInterfaceDef) Len() int

Len Get length of Stream

func (*StreamForInterfaceDef) Map

func (streamSelf *StreamForInterfaceDef) Map(fn func(interface{}, int) interface{}) *StreamForInterfaceDef

Map Map all items of Stream by function

func (*StreamForInterfaceDef) Minus

Minus Get all of this Stream but not in the given Stream

func (*StreamForInterfaceDef) Reject

func (streamSelf *StreamForInterfaceDef) Reject(fn func(interface{}, int) bool) *StreamForInterfaceDef

Reject Reject items of Stream by function

func (*StreamForInterfaceDef) Remove

func (streamSelf *StreamForInterfaceDef) Remove(index int) *StreamForInterfaceDef

Remove Remove an item by its index

func (*StreamForInterfaceDef) RemoveItem

func (streamSelf *StreamForInterfaceDef) RemoveItem(input ...interface{}) *StreamForInterfaceDef

RemoveItem Remove items from the Stream

func (*StreamForInterfaceDef) Reverse

func (streamSelf *StreamForInterfaceDef) Reverse() *StreamForInterfaceDef

Reverse Reverse Stream items

func (*StreamForInterfaceDef) Sort

func (streamSelf *StreamForInterfaceDef) Sort(fn Comparator[interface{}]) *StreamForInterfaceDef

Sort Sort Stream items by Comparator

func (*StreamForInterfaceDef) SortByIndex

func (streamSelf *StreamForInterfaceDef) SortByIndex(fn func(a, b int) bool) *StreamForInterfaceDef

SortByIndex Sort Stream items by function(index, index) bool

func (*StreamForInterfaceDef) ToArray

func (streamSelf *StreamForInterfaceDef) ToArray() []interface{}

ToArray Convert Stream to slice

type StreamSetDef

type StreamSetDef[T comparable, R comparable] struct {
	MapSetDef[T, *StreamDef[R]]
}

StreamSetDef StreamSet inspired by Collection utils

func NewStreamSet

func NewStreamSet[T comparable, R comparable]() *StreamSetDef[T, R]

NewStreamSet New StreamSet instance

func StreamSetFrom

func StreamSetFrom[T comparable, R comparable](list ...T) *StreamSetDef[T, R]

StreamSetFrom New StreamSet instance from a T array

func StreamSetFromArray

func StreamSetFromArray[T comparable, R comparable](list []T) *StreamSetDef[T, R]

StreamSetFromArray New StreamSet instance from a T array

func StreamSetFromMap

func StreamSetFromMap[T comparable, R comparable](theMap map[T]*StreamDef[R]) *StreamSetDef[T, R]

StreamSetFromMap New StreamSet instance from a map[T]R

func (*StreamSetDef[T, R]) Clone

func (streamSetSelf *StreamSetDef[T, R]) Clone() *StreamSetDef[T, R]

Clone Clone this StreamSet

func (*StreamSetDef[T, R]) Intersection

func (streamSetSelf *StreamSetDef[T, R]) Intersection(input *StreamSetDef[T, R]) *StreamSetDef[T, R]

Intersection Get the Intersection with this StreamSet and an another StreamSet

func (*StreamSetDef[T, R]) MinusStreams

func (streamSetSelf *StreamSetDef[T, R]) MinusStreams(input *StreamSetDef[T, R]) *StreamSetDef[T, R]

MinusStreams Minus the Stream values by their keys(keys will not be changed but Stream values will)

func (*StreamSetDef[T, R]) Union

func (streamSetSelf *StreamSetDef[T, R]) Union(input *StreamSetDef[T, R]) *StreamSetDef[T, R]

Union Union an another StreamSet object

type StreamSetForInterfaceDef

type StreamSetForInterfaceDef struct {
	SetForInterfaceDef
}

StreamSetForInterfaceDef Set inspired by Collection utils

var StreamSetForInterface StreamSetForInterfaceDef

StreamSetForInterface StreamSetForInterface utils instance

func NewStreamSetForInterface

func NewStreamSetForInterface() *StreamSetForInterfaceDef

NewStreamSetForInterface New StreamSetForInterface instance

func StreamSetForInterfaceFrom

func StreamSetForInterfaceFrom(list ...interface{}) *StreamSetForInterfaceDef

StreamSetForInterfaceFrom New StreamSetForInterface instance from a T array

func StreamSetForInterfaceFromArray

func StreamSetForInterfaceFromArray(list []interface{}) *StreamSetForInterfaceDef

StreamSetForInterfaceFromArray New StreamSetForInterface instance from a T array

func StreamSetForInterfaceFromMap

func StreamSetForInterfaceFromMap(theMap map[interface{}]*StreamForInterfaceDef) *StreamSetForInterfaceDef

StreamSetForInterfaceFromMap New StreamSetForInterface instance from a map[T]R

func StreamSetFromArrayInterface

func StreamSetFromArrayInterface(list []interface{}) *StreamSetForInterfaceDef

StreamSetFromArrayInterface New StreamSetForInterface instance from an array

func StreamSetFromInterface

func StreamSetFromInterface(list ...interface{}) *StreamSetForInterfaceDef

StreamSetFromInterface New StreamSetForInterface instance from an array

func (*StreamSetForInterfaceDef) Clone

func (streamSetSelf *StreamSetForInterfaceDef) Clone() *StreamSetForInterfaceDef

Clone Clone this StreamSetForInterface

func (*StreamSetForInterfaceDef) Intersection

func (streamSetSelf *StreamSetForInterfaceDef) Intersection(input *StreamSetForInterfaceDef) *StreamSetForInterfaceDef

Intersection Get the Intersection with this StreamSetForInterface and an another StreamSetForInterface

func (*StreamSetForInterfaceDef) IsSubsetByKey

func (streamSetSelf *StreamSetForInterfaceDef) IsSubsetByKey(input *StreamSetForInterfaceDef) bool

IsSubsetByKey TODO NOTE !!Duplicated!! returns true or false by checking if set1 is a subset of set2

func (*StreamSetForInterfaceDef) IsSupersetByKey

func (streamSetSelf *StreamSetForInterfaceDef) IsSupersetByKey(input *StreamSetForInterfaceDef) bool

IsSupersetByKey TODO NOTE !!Duplicated!! returns true or false by checking if set1 is a superset of set2

func (*StreamSetForInterfaceDef) Minus

Minus TODO NOTE !!Duplicated!! Get all of this StreamSetForInterface but not in the given StreamSetForInterface

func (*StreamSetForInterfaceDef) MinusStreams

func (streamSetSelf *StreamSetForInterfaceDef) MinusStreams(input *StreamSetForInterfaceDef) *StreamSetForInterfaceDef

MinusStreams Minus the Stream values by their keys(keys will not be changed but Stream values will)

func (*StreamSetForInterfaceDef) Union

Union Union an another StreamSetForInterface object

type Subscription

type Subscription[T any] struct {
	OnNext func(T)
}

Subscription the delegation/callback of MonadIO/Publisher

type SumType

type SumType struct {
	// contains filtered or unexported fields
}

SumType SumType contains a CompType list

func (SumType) Matches

func (typeSelf SumType) Matches(value ...interface{}) bool

Matches Check does it match the SumType

type Transformer

type Transformer[T any, R any] interface {
	TransformedBy() TransformerFunctor[T, R]
}

Transformer Define Transformer Pattern interface

type TransformerFunctor

type TransformerFunctor[T any, R any] func(T) R

TransformerFunctor Functor of Transform

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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