Skip to content

hemstreet/go-sliceable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Sliceable

Install

go get github.com/hemstreet/go-sliceable

High Level Theory

Implementation of Map, Reduce and Filter. Accept a slice, function and output pointer.

Basic implementation are:

  • Map(sliceInput, mapFunc, outputSlicePtr)
  • Reduce(sliceInput, reduceFunc, outputPtr)
  • Filter(sliceInput, filterFunc, outputSlicePtr)

Examples

Map

       type Foo struct {
           ID   int
       }
   
       // What you have
       var foos = []Foo{...}
   
       var ids []int
   
       err := sliceable.Map(foos, func(thing interface{}) interface{} {
          return thing.(Foo).ID
       }, &ids)

Reduce

    type Foo struct {
        Years int
    }

    var foos = []Foo{...}

    var totalYears int

    err := sliceable.Reduce(foos, func(thing interface{}) int {
        return thing.(Foo).Years
    }, &totalYears)

Filter

    type Foo struct {
        Org string
    }

    var foos = []Foo{...}

    var filteredFoos []Foo

   err := sliceable.Filter(foos, func(thing interface{}) bool {
        return thing.(Foo).Org  == "Enterprise"
    }, &filteredFoos)

About

Golang implementation of Filter, Map and Reduce

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages