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
- Host: GitHub
- URL: https://github.com/johncgriffin/yogofn
- Owner: JohnCGriffin
- Created: 2017-05-28T19:52:36.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-13T21:23:52.000Z (almost 9 years ago)
- Last Synced: 2025-08-14T00:24:09.847Z (7 months ago)
- Topics: functional-programming, golang
- Language: Go
- Size: 21.5 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.