mirror of
https://github.com/rwxrob/bonzai
synced 2024-11-18 15:25:45 +00:00
17 lines
475 B
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
|
|
}
|