Version 1.2.0
go_vector is a container data structure based on C++ std::Vector. go_vector brings functional programming and removes boilerplate code.
*Snippets from the documentation/examples/main.go*Construct an empty vector
var players GoVector.Vector
players = players.Init()
Append an element
players.PushBack(newPlayer)
Remove an element
players.RemoveAt(index)
Get element at index
players.At(index)
Set element at index
players.SetAt(index)
Map function
playerCopy := players.FpMap(nil) //putting nil invokes default behavior of just returning a copy of the vector
playerTrophiesDoubled := players.FpMap(func( player GoVector.T ) GoVector.T{
return player.(Player).trophies * 2
})
Reduce function
//noobTrophies is a vector of ints
proTrophieSum := noobTrophies.FpReduce(func(v1 GoVector.T, v2 GoVector.T) GoVector.T {
return v1.(int) + v2.(int)
})
//However, since golang supports the + operator of int and int we could just invoke the default behavior
proTrophieSum := noobTrophies.FpReduce(nil)
Filter function
noNoobs := players.FpFilter(func(player GoVector.T) bool {
//if the player has more than 1000 trophies, add them
return player.(Player).trophies > 1000
}) //There is no default behavior for filter
Sort a vector
//sort the noob trophies from greatest to least, reverse for least to greatest
noobTrophies.SortStruct(func(noob1 GoVector.T, noob2 GoVector.T) bool {
return noob1.(int) < noob2.(int)
})
To save you a stack overflow search here is how you push the dev branch to the release
git push origin dev:master