# `gno.land/p/moul/fp` Functional helpers over `[]any`: the map / filter / reduce set, plus the grouping and zipping pieces that usually get rewritten inline. ```go numbers := []any{1, 2, 3, 4, 5, 6} isEven := func(v any) bool { return v.(int)%2 == 0 } double := func(v any) any { return v.(int) * 2 } sum := func(a, b any) any { return a.(int) + b.(int) } evens := fp.Filter(numbers, isEven) // [2 4 6] bigger := fp.Map(evens, double) // [4 8 12] total := fp.Reduce(bigger, sum, 0) // 24 ``` ## The set | | | | --- | --- | | transform | `Map`, `FlatMap`, `Filter`, `Reduce` | | test | `All`, `Any`, `None`, `Find` | | reshape | `Chunk`, `Reverse`, `Flatten`, `Zip`, `Unzip`, `GroupBy` | Three named function types keep signatures readable: `Mapper func(any) any`, `Predicate func(any) bool`, `Reducer func(any, any) any`. ## Two things to know before using it - **Everything is `[]any`.** Gno has no generics, so element access means a type assertion in your own callback, and a wrong one panics at runtime instead of failing to compile. Keep slices homogeneous. - **Every call allocates a new slice.** Chaining four operations over a large collection allocates four times. That is fine for rendering a page and wrong for a hot path over persisted state, where a single explicit loop is both cheaper and clearer. `GroupBy` returns `map[any][]any`, so the key must be a comparable type. --- Part of **[moul/gno-contracts](https://github.com/moul/gno-contracts)** — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage. > ⚠️ **Disclaimer:** provided as-is, without warranty; not security-audited. Full disclaimer: [DISCLAIMER](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md).