Do arithmetic on functions. Treat slices like functions. Do what ever you want.
add1 := func(x float64) float64 {
return x + 1
}
add2 := func(x float64) float64 {
return x + 2
}
cmb := funk.Add(mult, div)
cmd(1) == add1(1) + add2(1)
cmd(1) == 5c := a.Then(b)
c(x) == a(b(x))f := func(x float64) float64 {
// ... do something complicated to x
return x
}
// Convert f into a curve that is has points between -100 and 100
// With a resolution of 1
c := funk.ToCurve(f, -100, 100, 1)
// Encode to json
buff, _ := json.Marshal(buff)
// Decode
newCurve := funk.Curve{}
json.Unmarshal(buff, &newCurve)
// Convert back to a Funk
newFunk := newCurve.ToFunk()
// Now the new function will approxomate the original
f(x) =~ newFunk(x)This will run each function in it's own goroutine.
a := func(x float64) float64 {
return x * 2
}
b := func(x float64) float64 {
return x * 5
}
c := func(x float64) float64 {
return x / 100
}
d := Pipe(a, b, c)
c(b(a(5))) == d(5)