fnmath

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package fnmath is a small suite of mathematical utilities working on seq.Seq

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Max

func Max[T constraints.Ordered](s, t T) T

Max is a seq.FuncCollect and a seq.FuncUpdate, for use with seq.Reduce or seq.UpdateMap, that returns the maximal element.

func Min

func Min[T constraints.Ordered](s, t T) T

Min is a seq.FuncCollect and a seq.FuncUpdate, for use with seq.Reduce or seq.UpdateMap, that returns the minimal element.

func Sum

func Sum[T constraints.Arithmetic](into, t T) T

Sum is a seq.FuncCollect and a seq.FuncUpdate, for use with seq.Reduce or seq.UpdateSlice, that sums up the elements it sees.

Types

type Stats

type Stats[N constraints.Arithmetic] struct {
	Sum, Min, Max N
	Count         int
}

Stats is the result structure used by MakeStats

func MakeStats

func MakeStats[N constraints.Integer | constraints.Float](s Stats[N], n N) Stats[N]

MakeStats is a seq.FuncCollect that computes basic numeric properties of a seq of numbers.

Example

 data := seq.SliceOfArgs(-1, 0, 1, 2, 3)
	optStats := seq.Reduce(MakeStats[int], Stats[int]{}, data)
 // The stats are now {Sum: 5, Min: -1, Max: 3, Count: 5}

Jump to

Keyboard shortcuts

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