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:
Olaoluwa Osuntokun 2022-12-06 18:32:06 -08:00
parent a347e405e8
commit adb239300f
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

13
fn/stream.go Normal file
View 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
}