functional

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: MIT Imports: 3 Imported by: 0

README

Go Functional

Go Functional provides a Go package called functional, which contains sub-packages, which offer Functional Programming capabilities to some of Go's data types, such as slice and maps.

Go Functional

Design Goals

  • near-zero cost abstraction, with allowances made for readability and flexibility
  • respectful of both Functional Programming and Go idioms
  • well defined behaviour
  • well tested
  • well benchmarked, so that time and space complexity can be known and documented

Functional.Fslice

Provides certain methods common to Functional Programming for operating on slices. Methods that return a slice are chainable.

  • Slice.Map() - takes a function that maps over every element, returning a transformed slice (chainable)
  • Slice.Filter() - takes a function that filters a slice to a smaller subset (chainable)
  • Slice.Includes() - returns true if a value was found in the slice
  • Slice.Some() - takes a function that returns a boolean. Returns true early if the function returned true once
  • Slice.Every() - takes a function that returns a boolean. Returns false early if the function returned false once
  • Slice.ToSlice() - returns the underlying slice
  • Slice.Reduce() - takes a function that behaves like an accumulator, returning a single value
  • Slice.Sort() - takes a function that sorts the slice, and returns the sorted slice (chainable)

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 a way to group the subpackages topgether Sub-packages include flsice and fmap, which operate on slice and maps respectively

Many methods are chainable, enhancing composability and expressiveness, which is what gives functional programming it's signature style.

Go Functional provides a near-zero cost abstraction for a great many use-cases, but will not do so for all. Use the right tool for the right job. Run the included benchmarks for performance characteristics.

Index

Constants

View Source
const Version = "v0.0.1"

Variables

View Source
var TestSuite = functionalTestSuite{
	LoremIpsumFilePath: "fslice/testdata/lorem_ipsum_%d_words.txt",
	LoremIpsumLengths:  []int{10, 100, 1_000, 10_000, 100_000},
}

Functions

func FsliceFrom

func FsliceFrom[T comparable](inputSlice []T) fslice.MethodSet[T]

convenience for fslice.From()

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
Package fslice implements a set of methods (see [MethodSet]) for operating on slices in a Functional Programming way.
Package fslice implements a set of methods (see [MethodSet]) for operating on slices in a Functional Programming way.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL