status-go/vendor/github.com/meirf/gopart
Pascal Precht 0bdb596d3b feat: introduce discord import tool 2022-10-28 09:52:26 +02:00
..
.gitignore feat: introduce discord import tool 2022-10-28 09:52:26 +02:00
.travis.yml feat: introduce discord import tool 2022-10-28 09:52:26 +02:00
LICENSE feat: introduce discord import tool 2022-10-28 09:52:26 +02:00
README.md feat: introduce discord import tool 2022-10-28 09:52:26 +02:00
doc.go feat: introduce discord import tool 2022-10-28 09:52:26 +02:00
gopart.go feat: introduce discord import tool 2022-10-28 09:52:26 +02:00

README.md

Go Type-Agnostic Collection Partitioning

GoDoc Travis

Type-agnostic partitioning for anything that can be indexed in Go - slices, arrays,strings. Inspired by Guava's Lists.partition. This tiny library alleviates the issue of partitioning collections with wide ranging types - Go lacks generics - by returning consecutive index ranges that can be used on any indexable object.

Usage

    ...
    // bigList can be any type
    for idxRange := range gopart.Partition(len(bigList), partitionSize) {
        bulkOperation(bigList[idxRange.Low:idxRange.High])
    }
    ...

Full Executable Example

Installation

# install the library:
go get github.com/meirf/gopart

// use in your .go code:
import (
    "github.com/meirf/gopart"
)

Implementation

The partitioning is done with a separate goroutine that passes the index ranges to a channel. This requires the use of a for...range loop, but adds concurrency and lowers memory usage (no slice of index ranges is stored anywhere).