Skip to content

Anondo/chunky

Repository files navigation

CHUNKY

Build Status License Project status

Not the package you needed but the package you deserved. Chunk the slices up by creating an iterator specifically for each data types with ease. Because you are lazy maybe?

Installing

go get -u github.com/Anondo/chunky

Usage

Import The Package

import "github.com/Anondo/chunky"

Create An Iterator & Iterate Over The Chunks

data := []int{}

for i := 0; i < 10000; i++ {
  data = append(data, i)
}

itr := chunky.IntIterator{
  Chunkable:   data,
  ChunkLength: 450,
}

itr.ChunkUp()

log.Println("Chunks:")

for itr.Next() {
  log.Println(itr.CurrentBlock)
}

OR

Use the whole chunk

log.Println(itr.Chunk)

Using The Factory Function

data := []int{}

for i := 0; i < 10000; i++ {
	data = append(data, i)
}

itr := chunky.NewIntIterator(data, 450)

log.Println("Chunks:")

for itr.Next() {
	log.Println(itr.GetCurrentBlock().([]int)) // Need to type cast because GetCurrentBlock returns an empty interface
}

You need to type cast the chunks to use it, as the factory functions return an Iterator interface. So to play with the actual chunk:

log.Println(itr.(*chunky.IntIterator).Chunk)

Try out the iterators for other data types as well.

Contributing

See the contributions guide here.

License

Chunky is licensed under the MIT License.

About

Chunk the chunkables with this GO thing

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages