slice
Package slice provides lodash/Array-style collection helpers for slices.
import "github.com/sahilkhaire/gox/slice"
Select a symbol below — each page explains what it does, shows Node.js vs Go comparisons, and includes a runnable example.
Functions
| Symbol | Node.js | Kind | Summary |
|---|---|---|---|
| Chunk | _.chunk(arr, n) | func | Chunk splits into sub-slices of size (lodash chunk). |
| Contains | arr.includes(x) | func | Contains reports whether v is in the slice (Array.includes). |
| Every | arr.every(fn) | func | Every reports whether fn is true for all elements (Array.every). |
| Filter | arr.filter(fn) | func | Filter keeps elements where fn returns true (Array.filter). |
| Find | arr.find(fn) | func | Find returns the first element matching fn, or zero and false (Array.find). |
| FindIndex | arr.findIndex(fn) | func | FindIndex returns the index of the first match, or -1 (Array.findIndex). |
| Flatten | _.flatten(arr) | func | Flatten flattens one level of nested slices (lodash flatten). |
| GroupBy | _.groupBy(arr, fn) | func | GroupBy groups elements by key from fn (lodash groupBy). |
| Map | arr.map(fn) | func | Map applies fn to each element (Array.map). |
| Reduce | arr.reduce(fn, init) | func | Reduce folds the slice (Array.reduce). |
| Some | arr.some(fn) | func | Some reports whether fn is true for any element (Array.some). |
| SortBy | _.sortBy(arr, fn) | func | SortBy returns a sorted copy ordered by fn's key (lodash sortBy). |
| Uniq | _.uniq(arr) | func | Uniq returns unique elements in first-seen order (lodash uniq). |