Documentation
¶
Overview ¶
Package functional implements Functional Programming capabilities for common go data structures. The root package offers nothing except for some globals, some helper functions, and to act as a namespace for the sub-packages. Sub-packages include pkg/github.com/sean9999/GoFunctional/fslice . "fmap" is on the roadmap. "fstruct" is being considered.
Many methods are chainable, and when possible return another fslice or fmap, rather than the underlying slice or map. This is what gives Go Functional is compasability, expressiveness, and lends it the signature Functional Programming style. enhancing composability and expressiveness, which is what gives functional programming it's signature style.
While for most use-cases Go Functional is _essentially_ a zero-cost abstraction, it is not _fundamentally_ so. There are use cases where the trade-off between expressiveness and performance is not acceptable. Use the right tool for the right job. Run the included benchmarks for performance characteristics, or view Go's cyclomatic complexity here: [https://goreportcard.com/report/github.com/sean9999/GoFunctional]
Example ¶
package main
import (
"fmt"
"github.com/fxtlabs/primes"
"github.com/sean9999/GoFunctional/fslice"
)
func main() {
// apply a FilterFunction and then a MapFunction to get squares of primes
inputNumbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
outputNumbers := fslice.From(inputNumbers).Filter(func(v int, _ int, _ []int) bool {
return primes.IsPrime(v)
}).Map(func(v int, _ int, _ []int) int {
return v * v
})
fmt.Println(outputNumbers)
}
Output: [4 9 25 49 121]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var TestSuite = functionalTestSuite{ LoremIpsumFilePath: "fslice/testdata/lorem_ipsum_%d_words.txt", LoremIpsumLengths: []int{10, 100, 1_000, 10_000, 100_000}, }
TestSuite provides convenience functions for tests and benchmarks see: ./bin/generate-test-data/ to generate test data
Functions ¶
func FsliceFrom ¶
func FsliceFrom[T comparable](inputSlice []T) fslice.MethodSet[T]
convenience for fslice.From
Example ¶
package main
import (
"fmt"
functional "github.com/sean9999/GoFunctional"
"github.com/sean9999/GoFunctional/fslice"
)
func main() {
// these methods are functionally equivalent
// import functional "github.com/sean9999/GoFunctional"
x := functional.FsliceFrom([]int{1, 2, 3})
// import "github.com/sean9999/GoFunctional/fslice"
y := fslice.From([]int{1, 2, 3})
fmt.Println(x, y)
}
Output: [1 2 3] [1 2 3]
func NewFslice ¶
func NewFslice[T comparable](length, capacity int) fslice.MethodSet[T]
convenience for fslice.New
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
bin
|
|
|
generate-test-data
command
|
|
|
Package fslice implements a set of methods for operating on slices in a Functional Programming way.
|
Package fslice implements a set of methods for operating on slices in a Functional Programming way. |
