functional

package
v0.0.0-...-8385335 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: Unlicense Imports: 1 Imported by: 0

Documentation

Overview

Package functional provides some basic map/filter/reduce tools for float64 and int.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterF

func FilterF(slice []float64, f ToBool) (out []float64)

FilterF applies f to every element in slice to produce a new slice containing the elements where f evaluates to true.

func MapF

func MapF(slice []float64, fns ...OneToOne) (out []float64)

MapF applies f to every element in slice to produce a new slice.

func Max

func Max(max, n float64) float64

Max is a TwoToOne that will return the larger of its arguments.

func Min

func Min(min, n float64) float64

Min is a TwoToOne that will return the smaller of its arguments.

func Prod

func Prod(accumulator, n float64) float64

Prod is a TwoToOne that will multiply the accumulator and n.

func ReduceF

func ReduceF(slice []float64, f TwoToOne) (out float64)

ReduceF applies f to every element in slice to produce an accumlated value `out`. in `f` the first argument is the accumulator, and the second argument is the current element from the slice.

func Sum

func Sum(accumulator, n float64) float64

Sum is a TwoToOne that will add the accumulator and n.

Types

type OneToOne

type OneToOne func(float64) float64

OneToOne takes a single argument and produces a single result.

func Add

func Add(a float64) OneToOne

Add produces a OneToOne that adds its argument by a number.

func Exp

func Exp(exp float64) OneToOne

Exp produces a OneToOne that exponentiates its argument by a number.

func Inv

func Inv() OneToOne

Inv produces a OneToOne that returns the multiplicative inverse of its argument.

func Mul

func Mul(a float64) OneToOne

Mul produces a OneToOne that multiplies its argument by a number.

func Truth

func Truth(predicate ToBool) OneToOne

Truth produces a OneToOne that returns 1 if predicate is true for its argument, or 0 if predicate is false.

type ToBool

type ToBool func(float64) bool

ToBool takes a single argument and produces a boolean.

func All

func All(predicates ...ToBool) ToBool

All returns a ToBool that returns true if all of the predicates evaluate to true.

func Any

func Any(predicates ...ToBool) ToBool

Any returns a ToBool that returns true if any of the predicates evaluate to true.

func Equal

func Equal(a float64) ToBool

Equal returns a ToBool that returns true if its arg is equal to a number.

func GreaterThan

func GreaterThan(a float64) ToBool

GreaterThan returns a ToBool that returns true if its arg is greater than a number.

func LessThan

func LessThan(a float64) ToBool

LessThan returns a ToBool that returns true if its arg is less than a number.

type TwoToOne

type TwoToOne func(float64, float64) float64

TwoToOne takes 2 arguments and produces a single result.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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