slice

package
v0.0.0-...-a81b4a7 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2017 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package slice implements operations on slices.

All operations act on slices of T. Use stencil to specialise to a type.

For example, in order to use a string version of this package, import it as

import (
	str_slice "github.com/sridharv/stencil/std/slice/T/string"
)

and run stencil on the importing package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(s []T, fn func(T) bool) bool

Any returns true if fn is true for all elements of s

func Any

func Any(s []T, fn func(T) bool) bool

Any returns true if fn is true for any elements of s

func Index

func Index(s []T, e T) int

Index returns the first index of e in s

func IndexFunc

func IndexFunc(s []T, fn func(T) bool) int

IndexFunc returns the index of the first element for which fn returns true. If no such element exists it returns -1.

func Pop

func Pop(a []T) (T, []T)

Pop removes the last element from a, returning an updating slice

func Reverse

func Reverse(a []T)

Reverse reverses a in place.

func Sort

func Sort(a []T, less func(a, b T) bool)

Sort sorts a using the comparison function less.

func SortStable

func SortStable(a []T, less func(a, b T) bool)

SortStable sorts a stably using the comparison function less.

Types

type T

type T interface{}

func Cut

func Cut(a []T, i, j int) []T

Cut removes all elements between i and j.

func Delete

func Delete(a []T, i int) []T

Delete removes the ith element from a and returns the resulting slice.

func DeleteUnordered

func DeleteUnordered(a []T, i int) []T

DeleteUnordered removes the ith element in a, without preserving order. It can be faster that Delete as it results in much fewer copies.

func Flatten

func Flatten(slices ...[]T) []T

Flatten returns a slice created by adding each element of each slice in slices

func Insert

func Insert(a []T, v T, i int) []T

Insert inserts v in a at index i and returns the new slice

func InsertSlice

func InsertSlice(a []T, v []T, i int) []T

InsertSlice inserts v into a at index i and returns the new slice

func Push

func Push(a []T, v T) []T

Push pushes v on to the end of a, returning an updated slice.

Jump to

Keyboard shortcuts

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