gwutil

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gwutil provides general-purpose utilities that are not used by the core of gowid but that have proved useful for several pre-canned widgets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlmostEqual

func AlmostEqual(a, b float64) bool

AlmostEqual returns true if its two arguments are within 1e-5 of each other.

func HamiltonAllocation

func HamiltonAllocation(counts []int, alloc int) []int

HamiltonAllocation implements the Hamilton Method (Largest remainder method) to calculate integral ratios. (Like it is used in some elections.)

This is shamelessly cribbed from https://excess.org/svn/urwid/contrib/trunk/rbreu_scrollbar.py

counts -- list of integers ('votes per party') alloc -- total amount to be allocated ('total amount of seats')

func IPow

func IPow(a, b int) int

IPow returns a raised to the bth power.

func If

func If(statement bool, a, b interface{}) interface{}

If is a convenience function for mimicking a ternary operator e.g. If(x<y, x, y).(int)

func LStripByte

func LStripByte(data []byte, s byte) []byte

LStripByte returns a slice of its first argument which contains all bytes up to but not including its second argument.

func LimitTo

func LimitTo(a, v, b int) int

LimitTo is a one-liner that uses Min and Max to bound a value. Assumes a <= b.

func Map

func Map(vs []string, f func(string) string) []string

Map is the traditional functional map function for strings.

func Max

func Max(i int, js ...int) int

Min returns the larger of >1 integer arguments.

func Min

func Min(i int, js ...int) int

Min returns the smaller of >1 integer arguments.

func OptionString

func OptionString(opt IOption) string

For fmt.Stringer

func ProfileHeap

func ProfileHeap(filename string)

ProfileHeap is a function I used when debugging and optimizing gowid. It writes a Go-heap-profile to the filename specified.

func Round

func Round(f float64) float64

Round returns a float64 representing the closest whole number to the supplied float64 argument.

func RoundFloatToInt

func RoundFloatToInt(val float32) int

RoundFloatToInt returns an int representing the closest int to the supplied float, rounding up or down.

func StartProfilingCPU

func StartProfilingCPU(filename string)

StartProfilingCPU is a function I used when debugging and optimizing gowid. It starts the Go-profiler with output going to the specified file.

func StopProfilingCPU

func StopProfilingCPU()

StopProfilingCPU will stop the CPU profiler.

func StringOfLength

func StringOfLength(r rune, n int) string

StringOfLength returns a string consisting of n runes.

func Sum

func Sum(input ...int) int

Sum is a variadic function that returns the sum of its integer arguments.

Types

type IOption

type IOption interface {
	IsNone() bool
	Value() interface{}
}

type Int64Option

type Int64Option struct {
	// contains filtered or unexported fields
}

Int64Option is intended to represent an Option[int]

func NoneInt64

func NoneInt64() Int64Option

func SomeInt64

func SomeInt64(x int64) Int64Option

func (Int64Option) IsNone

func (i Int64Option) IsNone() bool

func (Int64Option) String

func (i Int64Option) String() string

For fmt.Stringer

func (Int64Option) Val

func (i Int64Option) Val() int64

func (Int64Option) Value

func (i Int64Option) Value() interface{}

type IntOption

type IntOption struct {
	// contains filtered or unexported fields
}

IntOption is intended to represent an Option[int]

func NoneInt

func NoneInt() IntOption

func SomeInt

func SomeInt(x int) IntOption

func (IntOption) IsNone

func (i IntOption) IsNone() bool

func (IntOption) String

func (i IntOption) String() string

For fmt.Stringer

func (IntOption) Val

func (i IntOption) Val() int

func (IntOption) Value

func (i IntOption) Value() interface{}

type RuneOption

type RuneOption struct {
	// contains filtered or unexported fields
}

RuneOption is intended to represent an Option[rune]

func NoneRune

func NoneRune() RuneOption

func SomeRune

func SomeRune(x rune) RuneOption

func (RuneOption) IsNone

func (i RuneOption) IsNone() bool

func (RuneOption) String

func (i RuneOption) String() string

func (RuneOption) Val

func (i RuneOption) Val() rune

func (RuneOption) Value

func (i RuneOption) Value() interface{}

Jump to

Keyboard shortcuts

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