godash

package module
Version: v0.0.0-...-8358332 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2017 License: MIT Imports: 2 Imported by: 0

README

Godash

Utility functions for searching and manipulating slices in golang. Inspired by the Lodash library in Javascript.

View documentation

Documentation

Overview

Package godash provides utility functions for searching and manipulating slices in golang. Inspired by the Lodash library in Javascript.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindBy

func FindBy(slice interface{}, fn validator) (interface{}, error)

FindBy returns the first element of the slice that the provided validator function returns true for. The supplied function must accept an interface{} parameter and return bool. If the validator function does not return true for any values in the slice, nil is returned.

func FindIndex

func FindIndex(slice interface{}, value interface{}) (int, error)

FindIndex returns the index of the first element in a slice that equals the provided value. If the value is not found in the slice, -1 is returned.

func FindIndexBy

func FindIndexBy(slice interface{}, fn validator) (int, error)

FindIndexBy returns the index of the first element of a slice that the provided validator function returns true for. The supplied function must accept an interface{} parameter and return bool. If the validator function does not return true for any values in the slice, -1 is returned.

func FindLastBy

func FindLastBy(slice interface{}, fn validator) (interface{}, error)

FindLastBy returns the last element of the slice that the provided validator function returns true for. The supplied function must accept an interface{} parameter and return bool. If the validator function does not return true for any values in the slice, nil is returned.

func FindLastIndex

func FindLastIndex(slice interface{}, value interface{}) (int, error)

FindLastIndex returns the index of the last element in a slice that equals the provided value. If the value is not found in the slice, -1 is returned.

func Intersection

func Intersection(slice1 interface{}, slice2 interface{}) (interface{}, error)

Intersection creates a slice of unique values that were present in both of the provided slices. The order of the items in the resulting slice is determined by the first given slice. The new slice is returned as an interface{} and may need to have a type assertion applied to it afterwards.

func IntersectionBy

func IntersectionBy(slice1 interface{}, slice2 interface{}, fn mutator) (interface{}, error)

IntersectionBy passes items from two provided slices through a provided mutator function and creates a new slice with items that resulted in common mutated values. The supplied mutator function must accept an interface{} parameter and return interface{} with the value to be compared. The order and values of the items in the resulting slice are determined by the first given slice. The new slice is returned as an interface{} and may need to have a type assertion applied to it afterwards.

func Uniq

func Uniq(slice interface{}) (interface{}, error)

Uniq removes duplicate values from a slice and returns the new slice. The new slice is returned as an interface{} and may need to have a type assertion applied to it afterwards.

func Without

func Without(slice interface{}, values ...interface{}) (interface{}, error)

Without removes values from a slice and returns the new slice. It accepts a slice of any type as the first parameter, followed by a list of parameter values to remove from the slice. The additional values must be of the same type as the provided slice. If using a basic type, such as string or int, it is recommended to use the more specific functions, such as WithoutString or WithoutInt. Otherwise, if using this function directly, the returned result will need to have a type assertion applied.

func WithoutBy

func WithoutBy(slice interface{}, fn validator) (interface{}, error)

WithoutBy removes values from a slice based on output from a provided validator function and returns the new slice. The supplied function must accept an interface{} parameter and return bool. Values for which the validator function returns true will be removed from the slice.

func WithoutFloat32

func WithoutFloat32(slice []float32, values ...interface{}) ([]float32, error)

WithoutFloat32 removes float32 values from a float32 slice

func WithoutInt

func WithoutInt(slice []int, values ...interface{}) ([]int, error)

WithoutInt removes int values from an int slice

func WithoutInt8

func WithoutInt8(slice []int8, values ...interface{}) ([]int8, error)

WithoutInt8 removes int8 values from an int8 slice

func WithoutString

func WithoutString(slice []string, values ...interface{}) ([]string, error)

WithoutString removes string values from a string slice

Types

This section is empty.

Jump to

Keyboard shortcuts

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