Immutable and Lazy loading Golang library to deal with slices
koala never changes your collections
go get github.com/MehmetEminKaymaz/koala
It adds items to the source , also it is variadic function.
list = list.Add(24)//add 24 to the source in one task or
list = list.Add(24,25,26,27) //add 24,25,26 and 27 to the source in one taskIt returns data according to a given condition
list=list.Where(func(x interface{}) bool {
return x.(int)>=10
})list=list.Foreach(func(x interface{}) (y interface{}) {
y=x.(int)*x.(int)
return
})It returns a boolean value , if exist true else false
list=list.Contains(1)
//or
list = list.Contains(2,3,4,5,6)//variadic function
//you can also pass a sliceIt swaps task before execution
list=list.Add(24)
list=list.Add(25)
//so output should be [24,25]
//but
list = list.SwapTask(0,1) // it swaps Add(24) and Add(25) so output should be [25,24]
Tasks can not be execute before calling Do , so do function executes all task.
list=list.Add(24)
list=list.Add(25)
list = list.SwapTask(0,1)
result = list.Do().Value() // result = [25,24]
It returns the result
It deletes task before execute
list=list.Add(24)
list=list.Add(25)
list = list.SwapTask(0,1)
list=list.Cancel(2) // SwapTask is cancelled
//so output [24,25]
It deletes task in execution
It clear all tasks before execution
It returns lenght of the source //source must be slice or array
It reverse the source
Remove item from source using index
Get element from source using index
Skip items in source
Take N item from source
a:=[]int{1,2,3,4,5,6}
list,err:=koala.From(a)
check(err)
list=list.Add(10) //add item
list=list.Add(11,12,13,14)//its also variadic function
list=list.Where(func(x interface{}) bool {
return x.(int)>=10
})
list=list.Reverse()
list=list.Add(1000)
list=list.Cancel(1)//it cancels the last task immediately ( list.Add(1000) )
list=list.SwapTasks(0,1) // swaps list.Add(10) and list.Add(11,12,13,14)
list=list.Foreach(func(x interface{}) (y interface{}) {
y=x.(int)*x.(int)
return
})
list=list.Contains(a)
//list=list.Contains(100,196)
list=list.Do() // calls all tasks
fmt.Println(list.Value())