mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
b6154d0f8d
* feat: add Take, TakeWhile, FilterTake, Window, and Sliding functions Add five new slice manipulation functions with tests, examples, and documentation. * improve Take function safety and add benchmarks * rename FilterTake to TakeFilter and add README docs * remove Window and Sliding benchmarks * apply gofmt and fix linter errors * apply gofmt and fix linter errors
32 lines
573 B
Markdown
32 lines
573 B
Markdown
---
|
|
name: First
|
|
slug: first
|
|
sourceRef: find.go#L554
|
|
category: core
|
|
subCategory: find
|
|
playUrl: https://go.dev/play/p/ul45Z0y2EFO
|
|
variantHelpers:
|
|
- core#find#first
|
|
similarHelpers:
|
|
- core#slice#take
|
|
- core#slice#takewhile
|
|
- core#find#firstor
|
|
- core#find#firstorempty
|
|
- core#find#last
|
|
- core#find#lastor
|
|
- core#find#lastorempty
|
|
- core#find#nth
|
|
position: 260
|
|
signatures:
|
|
- "func First[T any](collection []T) (T, bool)"
|
|
---
|
|
|
|
Returns the first element of a collection and whether it exists.
|
|
|
|
```go
|
|
v, ok := lo.First([]int{1, 2, 3})
|
|
// v == 1, ok == true
|
|
```
|
|
|
|
|