lnd/fn/stream.go
Olaoluwa Osuntokun adb239300f
fn: add new fn (func utils) package for generic helper funcs
We start with a simple Map function that can be useful for transforming
objects on the fly.

We may want to eventually make this Taro pakage into a module so we can
just have everything in one place:
https://github.com/lightninglabs/taro/tree/main/chanutils.
2022-12-15 11:56:31 -08:00

14 lines
240 B
Go

package fn
// Map takes an input slice, and applies the function f to each element,
// yielding a new slice.
func Map[T1, T2 any](s []T1, f func(T1) T2) []T2 {
r := make([]T2, len(s))
for i, v := range s {
r[i] = f(v)
}
return r
}