slice

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map

func Map(slice interface{}, fn interface{}) interface{}

Map maps the slice using the mapper function fn. Map panics if slice is not a slice, fn is not a function that accepts a single argument of the slice type or fn does not have a single return value of the slice type. The returned value is a slice with same type as the return value of fn.

Examples

names := []string{"foo", "bar", "baz"}
uppercase := Map(names, strings.ToUpper).([]string)
// uppercase == []string{"FOO", "BAR", "BAZ"}

numbers := []int{1, 2, 4, 8}
doubled := Map(numbers, func(num int) int { return num*2 }).([]int)
// doubled == []int{2, 4, 8, 16}

Types

This section is empty.

Jump to

Keyboard shortcuts

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