functional.go

Related tags

functional.go
Overview

functional.go

Adding functional programming capabilities to golang with new generics

Any

x := []int{1, 2, 3, 4}

fmt.Println(f.Any(func(y int) bool { return y%2 == 0 }, x))

Filter

x := []int{1, 2, 3, 4}

fmt.Println(f.Filter(func(y int) bool {
  return y%2 == 0
}, x)

Id

fmt.Println(f.Id(5)

Map

x := []int{1, 2, 3, 4}

fmt.Println(f.Map(func(x int) int {
  return x * 2
}, x)

MapM_

x := []int{1, 2, 3, 4}

f.MapM_(func(x int) {
  fmt.Println(x)
}, x)

Reduce

x := []int{1, 2, 3, 4}

fmt.Println(f.Reduce(x, 0, func(r int, curr int) int {
  return curr + r
})

Zip

x := []int{1, 2, 3, 4}
y := []int{10, 9, 8, 7}

fmt.Println(f.Zip(x, y))
Owner
Will
There's a spacecraft blocking out the sky - Thom Yorke
Will
A collection of useful, performant, and threadsafe Go datastructures.

go-datastructures Go-datastructures is a collection of useful, performant, and threadsafe Go datastructures. NOTE: only tested with Go 1.3+. Augmented

Workiva 6.2k Sep 22, 2021
Generates data structure definitions from JSON files for any kind of programming language

Overview Archivist generates data structure definitions from JSON files for any kind of programming language. It also provides a library for golang to

Kingsgroup 43 Aug 4, 2021