billsutil

package
v0.0.0-...-afa3bba Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: Unlicense Imports: 4 Imported by: 0

Documentation

Overview

Package billsutil contains a set of miscellaneaous utilities Bill finds useful In particular it contains utilties for operating on slices using common functional idioms

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(n int) int

Abs returns the absolute value of an int

func AllInt

func AllInt(vs []int, f func(int) bool) bool

AllInt returns true if all of the ints in the slice satisfy the predicate f. The slice must be non empty

func FindInt

func FindInt(vs []int, val int) []int

FindInt returns a slice of all positions of val in the slice vs. If there are no occurrences, an empty slice is returned.

func IsPrime

func IsPrime(p int) bool

IsPrime is an inefficient test for whether an integer is prime or not

func MapChar

func MapChar(vs string, f func(rune) rune) string

MapChar returns a new slice containing the results of applying the function f to each string in the original slice.

func MapInt

func MapInt(vs []int, f func(int) int) []int

MapInt returns a new slice containing the results of applying the function f to each int in the original slice.

func Max

func Max(i, j int) int

Max returns the maximum of two ints

func Min

func Min(i, j int) int

Min returns the minimum of two ints

func MinArray

func MinArray(js []int) int

MinArray takes a []int and return the minimum element of the slice

func ReduceInt

func ReduceInt(vs []int, f func(int, int) int) int

ReduceInt returns the result of a pairwise application of the function through the slice The input slice must be at least length 2

func Reverse

func Reverse(s sort.Interface)

Reverse reverses any sortable collection and is very efficient. Note that it reverse in place, so it modifies the slice passed in This is the implementation of the stringutil.Reverse example at https://github.com/golang/example

func ReverseInt

func ReverseInt(is []int) []int

ReverseInt is a convenience method for reversing Int slices It makes a copy of the input to avoid mutating it.

func ReverseStr

func ReverseStr(str string) string

ReverseStr is a convenience method for reversing strings

func TimeIt

func TimeIt(start time.Time, name string) time.Duration

TimeIt is used as a defered function at the start of a function to time it

  Usage:
		func myFunction(n int) []bool {
			defer TimeIt(time.Now(), "myFunction")
			// rest of code goes here
		}

func TimedFunc

func TimedFunc(fn func()) time.Duration

TimedFunc takes any function that does not return a value and times it The time taken is returned as a time.Duration

Types

type RuneSlice

type RuneSlice []rune

RuneSlice attaches the methods of sort.Interface to []rune, for sorting and reversing

func (RuneSlice) Len

func (p RuneSlice) Len() int

func (RuneSlice) Less

func (p RuneSlice) Less(i, j int) bool

func (RuneSlice) Swap

func (p RuneSlice) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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