mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 14:45:23 +01:00
adb239300f
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.
14 lines
240 B
Go
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
|
|
}
|