goji

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

README

goji

string utils made easy

goji

Documentation

Overview

Package goji provides functional utils for int / float / string Slice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concat

func Concat()

Concat merges two slices.

func Difference

func Difference(lenI, lenJ int, comparator func(int, int) bool, handlers ...func(...int)) []int

Difference returns difference of array/slice I's values not included in the other given array J. lenI, lenJ is the length of array/slice I, J. comparator compares values from array/slice I, J.

func Every

func Every(n int, predict func(int) bool) bool

Every tests whether all elements pass the test implemented by predict. n is the number of elements. j is the index of array/slice.

func Fill

func Fill(fill func(int), n int, startEndIndex ...int)

Fill fills all elements from a start index to an end index with a static value. the end index is not included. n is the number of elements. start and end index are optional, default to zero and n.

func Filter

func Filter(n int, predict func(int) bool, handlers ...func(...int)) []int

Filter filters elements, n is the number of elements. predict check element with index i and returns true or false. handlers receive accumulated indexes idx from predict, if any.

func FindIndex

func FindIndex(n int, testing func(int) bool, fromIndex ...int) int

FindIndex returns the index of the first element that satisfies the provided testing function. Otherwise -1 is returned. n is the number of elements.

func FindLastIndex

func FindLastIndex(n int, testing func(int) bool, fromIndex ...int) int

FindLastIndex iterates over elements from right to left.

func Includes

func Includes(n int, comp func(int) bool) bool

Includes determines whether an array/slice includes a certain element, returning true or false. n is the number of elements. comp determines whether the given element with index j is found.

func Intersection

func Intersection(lenI, lenJ int, comparator func(int, int) bool, handlers ...func(...int)) []int

Intersection returns values that are included in both given array/slice.

func Join

func Join(join func(int) string, n int, sep ...string) string

Join joins all elements of array/slice into a string. The separator string sep is placed between elements in the resulting string. n is the number of elements. func join receive element index i and return a string.

func Map

func Map(n int, m func(int))

Map calls a provided function m on every element. n is the number of elements. m map element with index i.

func Max

func Max(x, y int) int

Max returns the larger of x or y.

func Min

func Min(x, y int) int

Min returns the smaller of x or y.

func Range

func Range(end int) []struct{}

Range creates a range of numbers progressing from zero up to, but not including end.

func Reverse

func Reverse(n int, swap func(int, int))

Reverse reverses an array/slice, n is the number of elements. swap swaps the elements with indexes i and j.

func Shuffle

func Shuffle(n int, swap func(int, int))

Shuffle randomizes the order of elements. n is the number of elements. swap swaps the elements with indexes i and j.

func Slice

func Slice(slice func(int, int), n int, startEndIndex ...int)

Slice returns a portion of array/slice selected from start to end (end not included). n is the number of elements. start and end indexes are optional, default to zero and n. start and end indexes are passed to slice func.

func Some

func Some(n int, predict func(int) bool) bool

Some tests whether at least one element pass the test implemented by predict. n is the number of elements. j is the index of array/slice.

func Sort

func Sort(n int, swap func(int, int), less func(int, int) bool)

Sort sorts elements, n is the number of elements. less compares the elements with indexes i and j. swap swaps the elements with indexes i and j.

Types

type Sorter added in v0.3.0

type Sorter struct {
	N        int
	SwapFunc func(i, j int)
	LessFunc func(i, j int) bool
}

Sorter implements Sort interface.

func (Sorter) Len added in v0.3.0

func (x Sorter) Len() int

func (Sorter) Less added in v0.3.0

func (x Sorter) Less(i, j int) bool

func (Sorter) Swap added in v0.3.0

func (x Sorter) Swap(i, j int)

Directories

Path Synopsis
example
pkg
float32util
Package float32util provides functional utils for float.
Package float32util provides functional utils for float.
intutil
Package intutil provides functional utils for int.
Package intutil provides functional utils for int.
strutil
Package strutil provides functional utils for string.
Package strutil provides functional utils for string.

Jump to

Keyboard shortcuts

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