mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
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.
This commit is contained in:
parent
a347e405e8
commit
adb239300f
13
fn/stream.go
Normal file
13
fn/stream.go
Normal file
@ -0,0 +1,13 @@
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue
Block a user