You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bonzai/fn/fn.go

17 lines
475 B
Go

// Copyright 2022 Robert S. Muhlestein.
// SPDX-License-Identifier: Apache-2.0
package fn
// Map executes an operator function provided on each item in the
// slice returning a new slice. If error handling is needed it should be
// handled within an enclosure within the function. This keeps
// signatures simple and functional.
func Map[I any, O any](slice []I, f func(in I) O) []O {
list := []O{}
for _, i := range slice {
list = append(list, f(i))
}
return list
}