An open API service indexing awesome lists of open source software.

https://github.com/johncgriffin/yogofn

Functional Map/Reduce/Filter for Golang
https://github.com/johncgriffin/yogofn

functional-programming golang

Last synced: 2 months ago
JSON representation

Functional Map/Reduce/Filter for Golang

Awesome Lists containing this project

README

          

# yogofn
Functional Map/Reduce/Filter for Golang

### install
go get github.com/johncgriffin/yogofn

Yogofn offers a few slice generating operations as alternatives to Go's for-loops.

For instance, let's find the max daily temperature range given two parallel lists of low and high daily temperatures.
Here's standard Go code given two float64 slices.

```
var maxDailyRange float64
for i:=0; i slice projection
- ``Filter(f,slice)`` -> slice selection
- ``Reduce(f,slice(s))`` -> scalar
- ``Every(f,slice)`` -> bool
- ``Any(f,slice)`` -> bool

Notice that because Reduce and Map can take more than one list, Zip is effected via

```
zipped := Map(func(x,y string) []string { return []string{x,y} }, xs, ys).([][]string)
```
A companion package is yogofn/reducers which contains simple but common scalar reductions for int and float64 numbers.

#### Reflection Performance

Not suprisingly, reflection slows down standard Go about 200 times. Using Go's type switch, a few optimizations
were placed into Map/Filter/Reduce
for common data types float64, int, and string. Those operations are implemented as normal typed Go loops.