fpgo

package module
Version: v1.5.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: 10 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
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
var actualInt int

m = MonadIO.Just(1)
actualInt = 0
m.Subscribe(Subscription{
  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 {
  v, _ := Maybe.Just(in).ToInt()
  return MonadIO.Just(v + 1)
})
actualInt = 0
m.Subscribe(Subscription{
  OnNext: func(in interface{}) {
    actualInt, _ = Maybe.Just(in).ToInt()
  },
})
fmt.Println(actualInt) // actualInt would be 2

Stream (inspired by Collection libs)

Example:

var s *StreamDef
var tempString = ""

s = Stream.FromArrayInt([]int{}).Append(1).Extend(Stream.FromArrayInt([]int{2, 3, 4})).Extend(Stream.FromArray([]interface{}{nil}))
tempString = ""
for _, v := range s.ToArray() {
  tempString += Maybe.Just(v).ToMaybe().ToString()
}
fmt.Println(tempString) // tempString would be "1234<nil>"
s = s.Distinct()
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
var stack Stack
var err error
var result interface{}

linkedListQueue := NewLinkedListQueue()
queue = linkedListQueue
stack = linkedListQueue
concurrentQueue := NewConcurrentQueue(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 interface{}
var timeout time.Duration

bufferedChannelQueue := NewBufferedChannelQueue(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, input interface{}) {
  // SPAWN: for ROOT
  if input == cmdSpawn {
    self.Spawn(func(self *ActorDef, 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, input interface{}) {
    // Ask cases: ROOT
    switch val := input.(type) {
    case *AskDef:
        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
result = Ask.New(1).AskOnce(actorRoot)
actual, _ = Maybe.Just(result).ToInt()
assert.Equal(t, expectedInt, actual)
// Ask with Timeout
// Result would be 20
result, _ = Ask.New(2).AskOnceWithTimeout(actorRoot, timeout)
actual, _ = Maybe.Just(result).ToInt()
// Ask channel
// Result would be 30
ch := Ask.New(3).AskChannel(actorRoot)
actual, _ = Maybe.Just(<-ch).ToInt()
close(ch)

// Timeout cases
// Result would be 0 (zero value, timeout)
result, err = Ask.New(-1).AskOnceWithTimeout(actorRoot, timeout)
actual, _ = Maybe.Just(result).ToInt()

Compose

Example:

var fn01 = func(args ...interface{}) []interface{} {
  val, _ := Maybe.Just(args[0]).ToInt()
  return SliceOf(val + 1)
}
var fn02 = func(args ...interface{}) []interface{} {
  val, _ := Maybe.Just(args[0]).ToInt()
  return SliceOf(val + 2)
}
var fn03 = func(args ...interface{}) []interface{} {
  val, _ := Maybe.Just(args[0]).ToInt()
  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

Maybe Maybe utils instance

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

None None utils instance

Functions

func Compose

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

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

func Concat added in v1.2.0

func Concat(mine []interface{}, slices ...[]interface{}) []interface{}

Concat Concat slices

func CurryParam1 added in v1.2.1

func CurryParam1(fn func(interface{}, ...interface{}) interface{}, a interface{}) func(...interface{}) interface{}

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

func CurryParam1ForSlice1 added in v1.3.0

func CurryParam1ForSlice1(fn func(interface{}, []interface{}) interface{}, a interface{}) func(...interface{}) interface{}

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

func CurryParam2 added in v1.2.1

func CurryParam2(fn func(interface{}, interface{}, ...interface{}) interface{}, a interface{}, b interface{}) func(...interface{}) interface{}

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

func CurryParam3 added in v1.2.1

func CurryParam3(fn func(interface{}, interface{}, interface{}, ...interface{}) interface{}, a interface{}, b interface{}, c interface{}) func(...interface{}) interface{}

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

func CurryParam4 added in v1.2.1

func CurryParam4(fn func(interface{}, interface{}, interface{}, interface{}, ...interface{}) interface{}, a interface{}, b interface{}, c interface{}, d interface{}) func(...interface{}) interface{}

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

func CurryParam5 added in v1.2.1

func CurryParam5(fn func(interface{}, interface{}, interface{}, interface{}, interface{}, ...interface{}) interface{}, a interface{}, b interface{}, c interface{}, d interface{}, e interface{}) func(...interface{}) interface{}

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

func CurryParam6 added in v1.2.1

func CurryParam6(fn func(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, ...interface{}) interface{}, a interface{}, b interface{}, c interface{}, d interface{}, e interface{}, f interface{}) func(...interface{}) interface{}

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

func Dedupe added in v1.2.1

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

Dedupe Returns a new list removing consecutive duplicates in list.

func Difference added in v1.2.1

func Difference(arrList ...[]interface{}) []interface{}

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 added in v1.2.1

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

Distinct removes duplicates.

Example

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

func DistinctRandom added in v1.2.2

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

DistinctRandom removes duplicates.(RandomOrder)

func Drop added in v1.2.1

func Drop(count int, list ...interface{}) []interface{}

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 added in v1.2.1

func DropEq(num interface{}, list ...interface{}) []interface{}

DropEq returns a new list after dropping the given item

Example:

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

func DropLast added in v1.2.1

func DropLast(count int, list ...interface{}) []interface{}

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 added in v1.2.1

func DropWhile(f Predicate, list ...interface{}) []interface{}

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 added in v1.2.2

func DuplicateMap(input map[interface{}]interface{}) map[interface{}]interface{}

DuplicateMap Return a new Map

func DuplicateSlice added in v1.2.1

func DuplicateSlice(list []interface{}) []interface{}

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 added in v1.2.1

func Every(f Predicate, list ...interface{}) 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 added in v1.2.1

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

Exists checks if given item exists in the list

Example:

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

func Filter added in v1.2.0

func Filter(fn func(interface{}, int) bool, input ...interface{}) []interface{}

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

func Flatten added in v1.2.1

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

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

func GroupBy added in v1.2.1

func GroupBy(grouper TransformerFunctor, list ...interface{}) map[interface{}][]interface{}

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(list ...interface{}) interface{}

Head returns first element of a slice

func Intersection added in v1.2.1

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

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

func IntersectionMapByKey added in v1.2.1

func IntersectionMapByKey(inputList ...map[interface{}]interface{}) map[interface{}]interface{}

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

func IsDistinct added in v1.2.1

func IsDistinct(list ...interface{}) bool

IsDistinct returns true if no two of the arguments are =

func IsEqual added in v1.2.1

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

IsEqual Returns true if both list are equal else returns false

func IsEqualMap added in v1.2.1

func IsEqualMap(map1, map2 map[interface{}]interface{}) bool

IsEqualMap Returns true if both maps are equal else returns false

func IsNil added in v1.3.0

func IsNil(obj interface{}) bool

IsNil Check is it nil

func IsPtr added in v1.3.2

func IsPtr(obj interface{}) bool

IsPtr Check is it a Ptr

func IsSubset added in v1.2.1

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

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

func IsSubsetMapByKey added in v1.2.1

func IsSubsetMapByKey(item1, item2 map[interface{}]interface{}) bool

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

func IsSuperset added in v1.2.1

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

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

func IsSupersetMapByKey added in v1.2.1

func IsSupersetMapByKey(item1, item2 map[interface{}]interface{}) bool

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

func IsZero added in v1.2.1

func IsZero(v interface{}) bool

IsZero Returns true if num is zero, else false

func Keys added in v1.2.1

func Keys(m map[interface{}]interface{}) []interface{}

Keys returns a slice of map's keys

func Kind added in v1.3.0

func Kind(obj interface{}) reflect.Kind

Kind Get Kind by reflection

func MakeNumericReturnForParam1ReturnBool1 added in v1.2.3

func MakeNumericReturnForParam1ReturnBool1(fn func(interface{}) bool) func(...interface{}) []interface{}

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

func MakeNumericReturnForSliceParamReturnBool1 added in v1.3.0

func MakeNumericReturnForSliceParamReturnBool1(fn func([]interface{}) bool) func(...interface{}) []interface{}

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

func MakeNumericReturnForVariadicParamReturnBool1 added in v1.2.3

func MakeNumericReturnForVariadicParamReturnBool1(fn func(...interface{}) bool) func(...interface{}) []interface{}

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

func MakeVariadicParam1 added in v1.2.1

func MakeVariadicParam1(fn func(interface{}) []interface{}) func(...interface{}) []interface{}

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

func MakeVariadicParam2 added in v1.2.1

func MakeVariadicParam2(fn func(interface{}, interface{}) []interface{}) func(...interface{}) []interface{}

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

func MakeVariadicParam3 added in v1.2.1

func MakeVariadicParam3(fn func(interface{}, interface{}, interface{}) []interface{}) func(...interface{}) []interface{}

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

func MakeVariadicParam4 added in v1.2.1

func MakeVariadicParam4(fn func(interface{}, interface{}, interface{}, interface{}) []interface{}) func(...interface{}) []interface{}

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

func MakeVariadicParam5 added in v1.2.1

func MakeVariadicParam5(fn func(interface{}, interface{}, interface{}, interface{}, interface{}) []interface{}) func(...interface{}) []interface{}

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

func MakeVariadicParam6 added in v1.2.1

func MakeVariadicParam6(fn func(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) []interface{}) func(...interface{}) []interface{}

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

func MakeVariadicReturn1 added in v1.2.1

func MakeVariadicReturn1(fn func(...interface{}) interface{}) func(...interface{}) []interface{}

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

func MakeVariadicReturn2 added in v1.2.1

func MakeVariadicReturn2(fn func(...interface{}) (interface{}, interface{})) func(...interface{}) []interface{}

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

func MakeVariadicReturn3 added in v1.2.1

func MakeVariadicReturn3(fn func(...interface{}) (interface{}, interface{}, interface{})) func(...interface{}) []interface{}

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

func MakeVariadicReturn4 added in v1.2.1

func MakeVariadicReturn4(fn func(...interface{}) (interface{}, interface{}, interface{}, interface{})) func(...interface{}) []interface{}

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

func MakeVariadicReturn5 added in v1.2.1

func MakeVariadicReturn5(fn func(...interface{}) (interface{}, interface{}, interface{}, interface{}, interface{})) func(...interface{}) []interface{}

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

func MakeVariadicReturn6 added in v1.2.1

func MakeVariadicReturn6(fn func(...interface{}) (interface{}, interface{}, interface{}, interface{}, interface{}, interface{})) func(...interface{}) []interface{}

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

func Map added in v1.2.0

func Map(fn TransformerFunctor, values ...interface{}) []interface{}

Map Map the values to the function from left to right

func MapIndexed added in v1.2.0

func MapIndexed(fn func(interface{}, int) interface{}, values ...interface{}) []interface{}

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 Merge added in v1.2.1

func Merge(map1, map2 map[interface{}]interface{}) map[interface{}]interface{}

Merge takes two inputs: map[interface{}]interface{} and map[interface{}]interface{} and merge two maps and returns a new map[interface{}]interface{}.

func Minus added in v1.2.1

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

Minus all of set1 but not in set2

func MinusMapByKey added in v1.2.1

func MinusMapByKey(set1, set2 map[interface{}]interface{}) map[interface{}]interface{}

MinusMapByKey all of set1 but not in set2

func PMap added in v1.2.1

func PMap(f TransformerFunctor, option *PMapOption, list ...interface{}) []interface{}

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 added in v1.2.1

func Partition(predicate Predicate, list ...interface{}) [][]interface{}

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

func Pipe added in v1.2.0

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

Pipe Pipe the functions from left to right

func Prepend added in v1.2.1

func Prepend(element interface{}, list []interface{}) []interface{}

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

func PtrOf

func PtrOf(v interface{}) *interface{}

PtrOf Return Ptr of a value

func Reduce added in v1.2.0

func Reduce(fn ReducerFunctor, memo interface{}, input ...interface{}) interface{}

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

func ReduceIndexed added in v1.2.0

func ReduceIndexed(fn func(interface{}, interface{}, int) interface{}, memo interface{}, input ...interface{}) interface{}

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

func Reject added in v1.2.0

func Reject(fn func(interface{}, int) bool, input ...interface{}) []interface{}

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

func Reverse added in v1.2.1

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

Reverse reverse the list

func SliceOf added in v1.1.3

func SliceOf(args ...interface{}) []interface{}

SliceOf Return Slice of varargs

func SliceToMap added in v1.2.1

func SliceToMap(defaultValue interface{}, input ...interface{}) map[interface{}]interface{}

SliceToMap Return Slice of varargs

func Some added in v1.2.1

func Some(f Predicate, list ...interface{}) 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 added in v1.2.0

func Sort(fn Comparator, input []interface{})

Sort Sort items by Comparator

func SortBySortDescriptors added in v1.2.0

func SortBySortDescriptors(sortDescriptors []SortDescriptor, input []interface{})

SortBySortDescriptors Sort items by sortDescriptors

func SortSlice added in v1.2.0

func SortSlice(fn Comparator, input ...interface{}) []interface{}

SortSlice Sort items by Comparator

func SortedListBySortDescriptors added in v1.2.0

func SortedListBySortDescriptors(sortDescriptors []SortDescriptor, input ...interface{}) []interface{}

SortedListBySortDescriptors Sort items by sortDescriptors and return value

func SplitEvery added in v1.2.1

func SplitEvery(size int, list ...interface{}) [][]interface{}

SplitEvery returns elements in equal length slices

func Tail added in v1.2.1

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

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

func Take added in v1.2.1

func Take(count int, list ...interface{}) []interface{}

Take returns the first n elements of the slice

func TakeLast added in v1.2.1

func TakeLast(count int, list ...interface{}) []interface{}

TakeLast returns the last n elements of the slice

func Trampoline added in v1.2.1

func Trampoline(fn func(...interface{}) ([]interface{}, bool, error), input ...interface{}) ([]interface{}, error)

Trampoline Trampoline

func Union added in v1.2.1

func Union(arrList ...[]interface{}) []interface{}

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

func UniqBy added in v1.2.1

func UniqBy(identify TransformerFunctor, list ...interface{}) []interface{}

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

func Values added in v1.2.1

func Values(m map[interface{}]interface{}) []interface{}

Values returns a slice of map's values

func Zip added in v1.2.1

func Zip(list1 []interface{}, list2 []interface{}) map[interface{}]interface{}

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

Types

type ActorDef added in v1.3.5

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

ActorDef Actor model inspired by Erlang/Akka

var Actor ActorDef

Actor Actor utils instance

func (*ActorDef) Close added in v1.3.5

func (actorSelf *ActorDef) Close()

Close Close the Actor

func (*ActorDef) GetChild added in v1.3.5

func (actorSelf *ActorDef) GetChild(id time.Time) *ActorDef

GetChild Get a child Actor by ID

func (*ActorDef) GetDefault added in v1.3.5

func (actorSelf *ActorDef) GetDefault() *ActorDef

GetDefault Get Default Actor

func (*ActorDef) GetID added in v1.3.6

func (actorSelf *ActorDef) GetID() time.Time

GetID Get ID time.Time

func (*ActorDef) GetParent added in v1.3.5

func (actorSelf *ActorDef) GetParent() *ActorDef

GetParent Get its parent Actor

func (*ActorDef) IsClosed added in v1.3.5

func (actorSelf *ActorDef) IsClosed() bool

IsClosed Check is Closed

func (*ActorDef) New added in v1.3.5

func (actorSelf *ActorDef) New(effect func(*ActorDef, interface{})) *ActorDef

New New Actor instance

func (*ActorDef) NewByOptions added in v1.3.5

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

NewByOptions New Actor by its options

func (*ActorDef) Send added in v1.3.5

func (actorSelf *ActorDef) Send(message interface{})

Send Send a message to the Actor

func (*ActorDef) Spawn added in v1.3.5

func (actorSelf *ActorDef) Spawn(effect func(*ActorDef, interface{})) *ActorDef

Spawn Spawn a new Actor with parent(this actor)

type ActorHandle added in v1.3.7

type ActorHandle interface {
	Send(message interface{})
}

ActorHandle A target could send messages

type AskDef added in v1.3.7

type AskDef struct {
	Message interface{}
	// contains filtered or unexported fields
}

AskDef Ask inspired by Erlang/Akka

var Ask AskDef

Ask Ask utils instance

func AskNewByOptionsGenerics added in v1.3.7

func AskNewByOptionsGenerics(message interface{}, ioCh chan interface{}) *AskDef

AskNewByOptionsGenerics New Ask by its options

func AskNewGenerics added in v1.3.7

func AskNewGenerics(message interface{}) *AskDef

AskNewGenerics New Ask instance

func (*AskDef) AskChannel added in v1.3.7

func (askSelf *AskDef) AskChannel(target ActorHandle) chan interface{}

AskChannel Sender Ask

func (*AskDef) AskOnce added in v1.3.7

func (askSelf *AskDef) AskOnce(target ActorHandle) interface{}

AskOnce Sender Ask

func (*AskDef) AskOnceWithTimeout added in v1.4.3

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

AskOnce Sender Ask with timeout

func (*AskDef) New added in v1.3.7

func (askSelf *AskDef) New(message interface{}) *AskDef

New New Ask instance

func (*AskDef) NewByOptions added in v1.3.7

func (askSelf *AskDef) NewByOptions(message interface{}, ioCh chan interface{}) *AskDef

NewByOptions New Ask by its options

func (*AskDef) Reply added in v1.3.7

func (askSelf *AskDef) Reply(response interface{})

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 v1.4.0

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

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

func NewBufferedChannelQueue added in v1.4.0

func NewBufferedChannelQueue(channelCapacity int, bufferSizeMaximum int, nodeHookPoolSize int) *BufferedChannelQueue

NewBufferedChannelQueue New BufferedChannelQueue instance from a Queue

func (*BufferedChannelQueue) Close added in v1.4.0

func (q *BufferedChannelQueue) Close()

Close Close the BufferedChannelQueue

func (*BufferedChannelQueue) Count added in v1.4.6

func (q *BufferedChannelQueue) Count() int

Count Count items

func (*BufferedChannelQueue) GetBufferSizeMaximum added in v1.4.4

func (q *BufferedChannelQueue) GetBufferSizeMaximum() int

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

func (*BufferedChannelQueue) GetChannel added in v1.4.6

func (q *BufferedChannelQueue) GetChannel() chan interface{}

GetChannel Get Channel(for Selecting channels usages)

func (*BufferedChannelQueue) GetFreeNodeHookPoolIntervalDuration added in v1.4.4

func (q *BufferedChannelQueue) GetFreeNodeHookPoolIntervalDuration() time.Duration

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

func (*BufferedChannelQueue) GetLoadFromPoolDuration added in v1.4.4

func (q *BufferedChannelQueue) GetLoadFromPoolDuration() time.Duration

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

func (*BufferedChannelQueue) GetNodeHookPoolSize added in v1.4.4

func (q *BufferedChannelQueue) GetNodeHookPoolSize() int

GetNodeHookPoolSize Get nodeHookPoolSize(the buffering node hooks ideal size)

func (*BufferedChannelQueue) IsClosed added in v1.4.4

func (q *BufferedChannelQueue) IsClosed() bool

IsClosed Is the BufferedChannelQueue closed

func (*BufferedChannelQueue) Offer added in v1.4.0

func (q *BufferedChannelQueue) Offer(val interface{}) error

Offer Offer the val(non-blocking)

func (*BufferedChannelQueue) Poll added in v1.4.0

func (q *BufferedChannelQueue) Poll() (interface{}, error)

Poll Poll the val(non-blocking)

func (*BufferedChannelQueue) Put added in v1.4.0

func (q *BufferedChannelQueue) Put(val interface{}) error

Put Put the val(non-blocking)

func (*BufferedChannelQueue) SetBufferSizeMaximum added in v1.4.0

func (q *BufferedChannelQueue) SetBufferSizeMaximum(size int) *BufferedChannelQueue

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

func (*BufferedChannelQueue) SetFreeNodeHookPoolIntervalDuration added in v1.4.0

func (q *BufferedChannelQueue) SetFreeNodeHookPoolIntervalDuration(duration time.Duration) *BufferedChannelQueue

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

func (*BufferedChannelQueue) SetLoadFromPoolDuration added in v1.4.0

func (q *BufferedChannelQueue) SetLoadFromPoolDuration(duration time.Duration) *BufferedChannelQueue

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

func (*BufferedChannelQueue) SetNodeHookPoolSize added in v1.4.0

func (q *BufferedChannelQueue) SetNodeHookPoolSize(size int) *BufferedChannelQueue

SetNodeHookPoolSize Set nodeHookPoolSize(the buffering node hooks ideal size)

func (*BufferedChannelQueue) Take added in v1.4.0

func (q *BufferedChannelQueue) Take() (interface{}, error)

Take Take the val(blocking)

func (*BufferedChannelQueue) TakeWithTimeout added in v1.4.0

func (q *BufferedChannelQueue) TakeWithTimeout(timeout time.Duration) (interface{}, error)

TakeWithTimeout Take the val(blocking), with timeout

type ChannelQueue added in v1.4.0

type ChannelQueue chan interface{}

ChannelQueue ChannelQueue inspired by Collection utils

func NewChannelQueue added in v1.4.0

func NewChannelQueue(capacity int) ChannelQueue

NewChannelQueue New ChannelQueue instance with capacity

func (ChannelQueue) Offer added in v1.4.0

func (q ChannelQueue) Offer(val interface{}) error

Offer Offer the val(non-blocking)

func (ChannelQueue) Poll added in v1.4.0

func (q ChannelQueue) Poll() (interface{}, error)

Poll Poll the val(non-blocking)

func (ChannelQueue) Put added in v1.4.0

func (q ChannelQueue) Put(val interface{}) error

Put Put the val(blocking)

func (ChannelQueue) PutWithTimeout added in v1.4.0

func (q ChannelQueue) PutWithTimeout(val interface{}, timeout time.Duration) error

PutWithTimeout Put the val(blocking), with timeout

func (ChannelQueue) Take added in v1.4.0

func (q ChannelQueue) Take() (interface{}, error)

Take Take the val(blocking)

func (ChannelQueue) TakeWithTimeout added in v1.4.0

func (q ChannelQueue) TakeWithTimeout(timeout time.Duration) (interface{}, error)

TakeWithTimeout Take the 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 added in v1.2.0

type Comparable interface {
	CompareTo(interface{}) int
}

Comparable Comparable interface able to be compared

type Comparator added in v1.2.0

type Comparator func(interface{}, interface{}) bool

Comparator Comparator Functor

type ConcurrentQueue added in v1.4.0

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

ConcurrentQueue ConcurrentQueue inspired by Collection utils

func NewConcurrentQueue added in v1.4.0

func NewConcurrentQueue(queue Queue) *ConcurrentQueue

NewConcurrentQueue New ConcurrentQueue instance from a Queue

func (*ConcurrentQueue) Offer added in v1.4.0

func (q *ConcurrentQueue) Offer(val interface{}) error

Offer Offer the val(non-blocking)

func (*ConcurrentQueue) Poll added in v1.4.0

func (q *ConcurrentQueue) Poll() (interface{}, error)

Poll Poll the val(non-blocking)

func (*ConcurrentQueue) Put added in v1.4.0

func (q *ConcurrentQueue) Put(val interface{}) error

Put Put the val(probably blocking)

func (*ConcurrentQueue) Take added in v1.4.0

func (q *ConcurrentQueue) Take() (interface{}, error)

Take Take the val(probably blocking)

type ConcurrentStack added in v1.4.2

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

ConcurrentStack ConcurrentStack inspired by Collection utils

func NewConcurrentStack added in v1.4.2

func NewConcurrentStack(stack Stack) *ConcurrentStack

NewConcurrentStack New ConcurrentStack instance from a Stack

func (*ConcurrentStack) Pop added in v1.4.2

func (q *ConcurrentStack) Pop() (interface{}, error)

Take Take the val(probably blocking)

func (*ConcurrentStack) Push added in v1.4.2

func (q *ConcurrentStack) Push(val interface{}) error

Put Put the val(probably blocking)

type CorDef

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

CorDef Cor Coroutine inspired by Python/Ecmascript/Lua

var Cor CorDef

Cor Cor utils instance

func (*CorDef) DoNotation

func (corSelf *CorDef) DoNotation(effect func(*CorDef) interface{}) interface{}

DoNotation Do Notation by function (inspired by Haskell one)

func (*CorDef) IsDone

func (corSelf *CorDef) IsDone() bool

IsDone Is the Cor done

func (*CorDef) IsStarted

func (corSelf *CorDef) IsStarted() bool

IsStarted Is the Cor started

func (*CorDef) New

func (corSelf *CorDef) New(effect func()) *CorDef

New New a Cor instance

func (*CorDef) NewAndStart

func (corSelf *CorDef) NewAndStart(effect func()) *CorDef

NewAndStart New a Cor instance and start it immediately

func (*CorDef) Start

func (corSelf *CorDef) Start()

Start Start the Cor

func (*CorDef) StartWithVal added in v1.1.0

func (corSelf *CorDef) StartWithVal(in interface{})

StartWithVal Start the Cor with an initial value

func (*CorDef) Yield

func (corSelf *CorDef) Yield() interface{}

Yield Yield back(nil)

func (*CorDef) YieldFrom

func (corSelf *CorDef) YieldFrom(target *CorDef, in interface{}) interface{}

YieldFrom Yield from a given Cor

func (*CorDef) YieldFromIO

func (corSelf *CorDef) YieldFromIO(target *MonadIODef) interface{}

YieldFromIO Yield from a given MonadIO

func (*CorDef) YieldRef

func (corSelf *CorDef) YieldRef(out interface{}) interface{}

YieldRef Yield a value

type CorOp

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

CorOp Cor Yield Operation/Delegation/Callback

type CurryDef

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

CurryDef Curry inspired by Currying in Java ways

var Curry CurryDef

Curry Curry utils instance

func (*CurryDef) Call

func (currySelf *CurryDef) Call(args ...interface{}) *CurryDef

Call Call the currying function by partial or all args

func (*CurryDef) IsDone

func (currySelf *CurryDef) IsDone() bool

IsDone Is the currying done

func (*CurryDef) MarkDone

func (currySelf *CurryDef) MarkDone()

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

func (*CurryDef) New

func (currySelf *CurryDef) New(fn func(c *CurryDef, args ...interface{}) interface{}) *CurryDef

New New Curry instance by function

func (*CurryDef) Result

func (currySelf *CurryDef) Result() interface{}

Result Get the result value of currying

type DoublyListItem added in v1.4.0

type DoublyListItem struct {
	Next *DoublyListItem
	Prev *DoublyListItem

	Val *interface{}
}

DoublyListItem DoublyListItem inspired by Collection utils

func (*DoublyListItem) AddFirst added in v1.4.0

func (listItem *DoublyListItem) AddFirst(input *DoublyListItem) *DoublyListItem

AddFirst Add the input item to the first position

func (*DoublyListItem) AddLast added in v1.4.0

func (listItem *DoublyListItem) AddLast(input *DoublyListItem) *DoublyListItem

AddLast Add the input item to the last

func (*DoublyListItem) Count added in v1.4.0

func (listItem *DoublyListItem) Count() int

Count Count items

func (*DoublyListItem) First added in v1.4.0

func (listItem *DoublyListItem) First() *DoublyListItem

First Get the First one

func (*DoublyListItem) Last added in v1.4.0

func (listItem *DoublyListItem) Last() *DoublyListItem

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 added in v1.2.0

type FieldSortDescriptor struct {
	SimpleSortDescriptor
	// contains filtered or unexported fields
}

FieldSortDescriptor FieldSortDescriptor implemented by Reflection(by FieldName)

func NewFieldSortDescriptor added in v1.2.0

func NewFieldSortDescriptor(fieldName string, ascending bool) FieldSortDescriptor

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

func (FieldSortDescriptor) GetFieldName added in v1.2.0

func (descriptor FieldSortDescriptor) GetFieldName() string

GetFieldName Get the fieldName to sort

func (FieldSortDescriptor) SetFieldName added in v1.2.0

func (descriptor FieldSortDescriptor) SetFieldName(val string)

SetFieldName Set the fieldName to sort

func (FieldSortDescriptor) TransformedBy added in v1.2.0

func (descriptor FieldSortDescriptor) TransformedBy() TransformerFunctor

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) IsClosed added in v1.3.5

func (handlerSelf *HandlerDef) IsClosed() bool

IsClosed Check is Closed

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 v1.4.0

type LinkedListItem struct {
	Next *LinkedListItem

	Val *interface{}
}

LinkedListItem LinkedListItem inspired by Collection utils

func (*LinkedListItem) AddLast added in v1.4.0

func (listItem *LinkedListItem) AddLast(input *LinkedListItem) *LinkedListItem

AddLast Add the input item to the last

func (*LinkedListItem) Count added in v1.4.0

func (listItem *LinkedListItem) Count() int

Count Count items

func (*LinkedListItem) Last added in v1.4.0

func (listItem *LinkedListItem) Last() *LinkedListItem

Last Get the Last one

type LinkedListQueue added in v1.4.0

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

LinkedListQueue LinkedListQueue inspired by Collection utils

func NewLinkedListQueue added in v1.4.0

func NewLinkedListQueue() *LinkedListQueue

NewLinkedListQueue New LinkedListQueue instance

func (*LinkedListQueue) Clear added in v1.4.0

func (q *LinkedListQueue) Clear()

CLear Clear all data

func (*LinkedListQueue) ClearNodePool added in v1.4.0

func (q *LinkedListQueue) ClearNodePool()

ClearNodePool Clear cached LinkedListItem nodes in nodePool

func (*LinkedListQueue) Count added in v1.4.0

func (q *LinkedListQueue) Count() int

Count Count Items

func (*LinkedListQueue) KeepNodePoolCount added in v1.4.0

func (q *LinkedListQueue) KeepNodePoolCount(n int)

KeepNodePoolCount Decrease/Increase LinkedListItem nodes to n items

func (*LinkedListQueue) Offer added in v1.4.0

func (q *LinkedListQueue) Offer(val interface{}) error

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

func (*LinkedListQueue) Peek added in v1.4.0

func (q *LinkedListQueue) Peek() (interface{}, error)

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

func (*LinkedListQueue) Poll added in v1.4.0

func (q *LinkedListQueue) Poll() (interface{}, error)

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

func (*LinkedListQueue) Pop added in v1.4.0

func (q *LinkedListQueue) Pop() (interface{}, error)

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

func (*LinkedListQueue) Push added in v1.4.0

func (q *LinkedListQueue) Push(val interface{}) error

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

func (*LinkedListQueue) Put added in v1.4.0

func (q *LinkedListQueue) Put(val interface{}) error

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

func (*LinkedListQueue) Shift added in v1.4.0

func (q *LinkedListQueue) Shift() (interface{}, error)

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

func (*LinkedListQueue) Take added in v1.4.0

func (q *LinkedListQueue) Take() (interface{}, error)

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

func (*LinkedListQueue) Unshift added in v1.4.0

func (q *LinkedListQueue) Unshift(val interface{}) error

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

type MaybeDef

type MaybeDef interface {
	Just(in interface{}) MaybeDef
	Or(or interface{}) interface{}
	CloneTo(dest interface{}) MaybeDef
	Clone() MaybeDef
	FlatMap(fn func(interface{}) MaybeDef) MaybeDef
	ToString() string
	ToPtr() *interface{}
	ToMaybe() MaybeDef
	ToFloat64() (float64, error)
	ToFloat32() (float32, error)
	ToInt() (int, error)
	ToInt32() (int32, error)
	ToInt64() (int64, error)
	ToBool() (bool, error)
	Let(fn func())
	Unwrap() 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

type MonadIODef

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

MonadIODef MonadIO inspired by Rx/Observable

var MonadIO MonadIODef

MonadIO MonadIO utils instance

func (*MonadIODef) Eval added in v1.3.2

func (monadIOSelf *MonadIODef) Eval() interface{}

Eval Eval the value right now(sync)

func (*MonadIODef) FlatMap

func (monadIOSelf *MonadIODef) FlatMap(fn func(interface{}) *MonadIODef) *MonadIODef

FlatMap FlatMap the MonadIO by function

func (MonadIODef) Just

func (monadIOSelf MonadIODef) Just(in interface{}) *MonadIODef

Just New MonadIO by a given value

func (*MonadIODef) New

func (monadIOSelf *MonadIODef) New(effect func() interface{}) *MonadIODef

New New MonadIO by effect function

func (*MonadIODef) ObserveOn

func (monadIOSelf *MonadIODef) ObserveOn(h *HandlerDef) *MonadIODef

ObserveOn Observe the MonadIO on the specific Handler

func (*MonadIODef) Subscribe

func (monadIOSelf *MonadIODef) Subscribe(s Subscription) *Subscription

Subscribe Subscribe the MonadIO by Subscription

func (*MonadIODef) SubscribeOn

func (monadIOSelf *MonadIODef) SubscribeOn(h *HandlerDef) *MonadIODef

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 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 added in v1.2.1

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 added in v1.2.0

type Predicate func(interface{}) bool

Predicate Predicate Functor

type PredicateErr added in v1.2.1

type PredicateErr func(interface{}, 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 struct {
	// contains filtered or unexported fields
}

PublisherDef Publisher inspired by Rx/NotificationCenter/PubSub

var Publisher PublisherDef

Publisher Publisher utils instance

func (*PublisherDef) Map

func (publisherSelf *PublisherDef) Map(fn func(interface{}) interface{}) *PublisherDef

Map Map the Publisher in order to make a broadcasting chain

func (*PublisherDef) New

func (publisherSelf *PublisherDef) New() *PublisherDef

New New a Publisher

func (*PublisherDef) Publish

func (publisherSelf *PublisherDef) Publish(result interface{})

Publish Publish a value to its subscribers or next chains

func (*PublisherDef) Subscribe

func (publisherSelf *PublisherDef) Subscribe(sub Subscription) *Subscription

Subscribe Subscribe the Publisher by Subscription

func (*PublisherDef) SubscribeOn

func (publisherSelf *PublisherDef) SubscribeOn(h *HandlerDef) *PublisherDef

SubscribeOn Subscribe the Publisher on the specific Handler

func (*PublisherDef) Unsubscribe

func (publisherSelf *PublisherDef) Unsubscribe(s *Subscription)

Unsubscribe Unsubscribe the publisher by the Subscription

type Queue added in v1.4.0

type Queue interface {
	Put(val interface{}) error
	Take() (interface{}, error)
	Offer(val interface{}) error
	Poll() (interface{}, error)
}

Queue Queue inspired by Collection utils

type ReducerFunctor added in v1.2.1

type ReducerFunctor func(interface{}, interface{}) interface{}

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 added in v1.2.2

type SetDef map[interface{}]interface{}

SetDef Set inspired by Collection utils

var Set SetDef

Set Set utils instance

func SetFrom added in v1.2.2

func SetFrom(list ...interface{}) *SetDef

SetFrom New Set instance from a interface{} array

func SetFromArray added in v1.2.2

func SetFromArray(list []interface{}) *SetDef

SetFromArray New Set instance from a interface{} array

func SetFromArrayInterface added in v1.2.2

func SetFromArrayInterface(list []interface{}) *SetDef

SetFromArrayInterface New Set instance from an array

func SetFromInterface added in v1.2.2

func SetFromInterface(list ...interface{}) *SetDef

SetFromInterface New Set instance from an array

func SetFromMap added in v1.2.2

func SetFromMap(theMap map[interface{}]interface{}) *SetDef

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

func (*SetDef) Add added in v1.2.2

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

Add Add items into the Set

func (*SetDef) Clone added in v1.2.2

func (setSelf *SetDef) Clone() *SetDef

Clone Clone this Set

func (*SetDef) ContainsKey added in v1.2.3

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

ContainsKey Check the key exists or not in the Set

func (*SetDef) ContainsValue added in v1.2.3

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

ContainsValue Check the value exists or not in the Set

func (*SetDef) Get added in v1.2.3

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

Get Get items from the Set

func (*SetDef) Intersection added in v1.2.2

func (setSelf *SetDef) Intersection(input *SetDef) *SetDef

Intersection Get the Intersection with this Set and an another Set

func (*SetDef) IsSubsetByKey added in v1.2.3

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

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

func (*SetDef) IsSupersetByKey added in v1.2.3

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

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

func (*SetDef) Keys added in v1.2.3

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

Keys Convert Set to slice

func (*SetDef) MapKey added in v1.2.3

func (setSelf *SetDef) MapKey(fn TransformerFunctor) *SetDef

MapKey Map all keys of Set by function

func (*SetDef) MapValue added in v1.2.3

func (setSelf *SetDef) MapValue(fn TransformerFunctor) *SetDef

MapValue Map all values of Set by function

func (*SetDef) Minus added in v1.2.2

func (setSelf *SetDef) Minus(input *SetDef) *SetDef

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

func (*SetDef) RemoveKeys added in v1.2.3

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

RemoveKeys Remove keys from the Set

func (*SetDef) RemoveValues added in v1.2.3

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

RemoveValues Remove values from the Set

func (*SetDef) Set added in v1.2.3

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

Set Set items to the Set

func (*SetDef) Size added in v1.2.2

func (setSelf *SetDef) Size() int

Size Get size

func (*SetDef) Union added in v1.2.2

func (setSelf *SetDef) Union(input *SetDef) *SetDef

Union Union an another Set object

func (*SetDef) Values added in v1.2.3

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

Values Convert Set to slice

type SimpleSortDescriptor added in v1.2.0

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

SimpleSortDescriptor SimpleSortDescriptor implemented by TransformerFunctor

func NewSimpleSortDescriptor added in v1.2.0

func NewSimpleSortDescriptor(transformFn TransformerFunctor, ascending bool) SimpleSortDescriptor

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

func (SimpleSortDescriptor) IsAscending added in v1.2.0

func (descriptor SimpleSortDescriptor) IsAscending() bool

IsAscending Check is this SortDescriptor sorting by ascending

func (SimpleSortDescriptor) SetAscending added in v1.2.0

func (descriptor SimpleSortDescriptor) SetAscending(val bool)

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

func (SimpleSortDescriptor) TransformedBy added in v1.2.0

func (descriptor SimpleSortDescriptor) TransformedBy() TransformerFunctor

TransformedBy Get the TransformerFunctor of this SortDescriptor

type SortDescriptor added in v1.2.0

type SortDescriptor interface {
	Transformer

	IsAscending() bool
	SetAscending(bool)
}

SortDescriptor Define a Transformer Pattern SortDescriptor

type SortDescriptorsBuilder added in v1.2.0

type SortDescriptorsBuilder []SortDescriptor

SortDescriptorsBuilder SortDescriptorsBuilder for composing SortDescriptor list and sorting data

func NewSortDescriptorsBuilder added in v1.2.0

func NewSortDescriptorsBuilder() SortDescriptorsBuilder

NewSortDescriptorsBuilder Generate a new SortDescriptorsBuilder

func (SortDescriptorsBuilder) GetSortDescriptors added in v1.2.0

func (builder SortDescriptorsBuilder) GetSortDescriptors() []SortDescriptor

GetSortDescriptors Get sortDescriptors

func (SortDescriptorsBuilder) Sort added in v1.2.0

func (builder SortDescriptorsBuilder) Sort(input []interface{})

Sort Sort by sortDescriptors

func (SortDescriptorsBuilder) ThenWith added in v1.2.0

ThenWith Append a SortDescriptor

func (SortDescriptorsBuilder) ThenWithFieldName added in v1.2.0

func (builder SortDescriptorsBuilder) ThenWithFieldName(fieldName string, ascending bool) SortDescriptorsBuilder

ThenWithFieldName Use FieldName as a SortDescriptor

func (SortDescriptorsBuilder) ThenWithTransformerFunctor added in v1.2.0

func (builder SortDescriptorsBuilder) ThenWithTransformerFunctor(transformFn TransformerFunctor, ascending bool) SortDescriptorsBuilder

ThenWithTransformerFunctor Use TransformerFunctor as a SortDescriptor

func (SortDescriptorsBuilder) ToSortedList added in v1.2.0

func (builder SortDescriptorsBuilder) ToSortedList(input ...interface{}) []interface{}

ToSortedList Get the sorted result

type Stack added in v1.4.0

type Stack interface {
	Push(val interface{}) error
	Pop() (interface{}, error)
}

Stack Stack inspired by Collection utils

type StreamDef

type StreamDef []interface{}

StreamDef Stream inspired by Collection utils

var Stream StreamDef

Stream Stream utils instance

func (*StreamDef) Append

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

Append Append an item to Stream

func (*StreamDef) Clone added in v1.2.2

func (streamSelf *StreamDef) Clone() *StreamDef

Clone Clone this Stream

func (*StreamDef) Concat added in v1.2.0

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

Concat Concat Stream by another slices

func (*StreamDef) Contains added in v1.2.2

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

Contains Check the item exists or not in the Stream

func (*StreamDef) Distinct

func (streamSelf *StreamDef) Distinct() *StreamDef

Distinct Filter duplicated items and return a new Stream instance

func (*StreamDef) Extend

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

Extend Extend Stream by another Stream(s)

func (*StreamDef) Filter

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

Filter Filter items of Stream by function

func (*StreamDef) FilterNotNil added in v1.2.2

func (streamSelf *StreamDef) FilterNotNil() *StreamDef

FilterNotNil Filter not nil items and return a new Stream instance

func (*StreamDef) From added in v1.2.3

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

From New Stream instance from a interface{} array

func (*StreamDef) FromArray

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

FromArray New Stream instance from an interface{} array

func (*StreamDef) FromArrayBool

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

FromArrayBool New Stream instance from a bool array

func (*StreamDef) FromArrayByte added in v1.2.0

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

FromArrayByte New Stream instance from an int8 array

func (*StreamDef) FromArrayFloat32

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

FromArrayFloat32 New Stream instance from a float32 array

func (*StreamDef) FromArrayFloat64

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

FromArrayFloat64 New Stream instance from a float64 array

func (*StreamDef) FromArrayInt

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

FromArrayInt New Stream instance from an int array

func (*StreamDef) FromArrayInt16 added in v1.2.0

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

FromArrayInt16 New Stream instance from an int16 array

func (*StreamDef) FromArrayInt32

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

FromArrayInt32 New Stream instance from an int32 array

func (*StreamDef) FromArrayInt64

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

FromArrayInt64 New Stream instance from an int64 array

func (*StreamDef) FromArrayInt8 added in v1.2.0

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

FromArrayInt8 New Stream instance from an int8 array

func (*StreamDef) FromArrayMaybe

func (streamSelf *StreamDef) FromArrayMaybe(old []MaybeDef) *StreamDef

FromArrayMaybe FromArrayMaybe New Stream instance from a Maybe array

func (*StreamDef) FromArrayString

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

FromArrayString New Stream instance from a string array

func (*StreamDef) Get

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

Get Get an item of Stream by its index

func (*StreamDef) Intersection added in v1.2.2

func (streamSelf *StreamDef) Intersection(input *StreamDef) *StreamDef

Intersection Get the Intersection with this Stream and an another Stream

func (*StreamDef) IsSubset added in v1.2.2

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

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

func (*StreamDef) IsSuperset added in v1.2.2

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

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

func (*StreamDef) Len

func (streamSelf *StreamDef) Len() int

Len Get length of Stream

func (*StreamDef) Map

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

Map Map all items of Stream by function

func (*StreamDef) Minus added in v1.2.2

func (streamSelf *StreamDef) Minus(input *StreamDef) *StreamDef

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

func (*StreamDef) Reject added in v1.2.2

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

Reject Reject items of Stream by function

func (*StreamDef) Remove

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

Remove Remove an item by its index

func (*StreamDef) RemoveItem added in v1.2.2

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

RemoveItem Remove items from the Stream

func (*StreamDef) Reverse added in v1.2.2

func (streamSelf *StreamDef) Reverse() *StreamDef

Reverse Reverse Stream items

func (*StreamDef) Sort

func (streamSelf *StreamDef) Sort(fn Comparator) *StreamDef

Sort Sort Stream items by Comparator

func (*StreamDef) SortByIndex added in v1.2.0

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

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

func (*StreamDef) ToArray

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

ToArray Convert Stream to slice

type StreamSetDef added in v1.2.3

type StreamSetDef struct {
	SetDef
}

StreamSetDef Set inspired by Collection utils

var StreamSet StreamSetDef

StreamSet StreamSet utils instance

func NewStreamSet added in v1.2.3

func NewStreamSet() *StreamSetDef

NewStreamSet New StreamSet instance

func StreamSetFrom added in v1.2.3

func StreamSetFrom(list ...interface{}) *StreamSetDef

StreamSetFrom New StreamSet instance from a T array

func StreamSetFromArray added in v1.2.3

func StreamSetFromArray(list []interface{}) *StreamSetDef

StreamSetFromArray New StreamSet instance from a T array

func StreamSetFromArrayInterface added in v1.2.3

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

StreamSetFromArrayInterface New StreamSet instance from an array

func StreamSetFromInterface added in v1.2.3

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

StreamSetFromInterface New StreamSet instance from an array

func StreamSetFromMap added in v1.2.3

func StreamSetFromMap(theMap map[interface{}]*StreamDef) *StreamSetDef

StreamSetFromMap New StreamSet instance from a map[T]R

func (*StreamSetDef) Clone added in v1.2.3

func (streamSetSelf *StreamSetDef) Clone() *StreamSetDef

Clone Clone this StreamSet

func (*StreamSetDef) Intersection added in v1.2.3

func (streamSetSelf *StreamSetDef) Intersection(input *StreamSetDef) *StreamSetDef

Intersection Get the Intersection with this StreamSet and an another StreamSet

func (*StreamSetDef) IsSubsetByKey added in v1.2.3

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

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

func (*StreamSetDef) IsSupersetByKey added in v1.2.3

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

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

func (*StreamSetDef) Minus added in v1.2.3

func (streamSetSelf *StreamSetDef) Minus(input *StreamSetDef) *StreamSetDef

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

func (*StreamSetDef) MinusStreams added in v1.2.3

func (streamSetSelf *StreamSetDef) MinusStreams(input *StreamSetDef) *StreamSetDef

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

func (*StreamSetDef) Union added in v1.2.3

func (streamSetSelf *StreamSetDef) Union(input *StreamSetDef) *StreamSetDef

Union Union an another StreamSet object

type Subscription

type Subscription struct {
	OnNext func(interface{})
}

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 added in v1.2.0

type Transformer interface {
	TransformedBy() TransformerFunctor
}

Transformer Define Transformer Pattern interface

type TransformerFunctor added in v1.2.0

type TransformerFunctor func(interface{}) interface{}

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