mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
28 lines
497 B
Markdown
28 lines
497 B
Markdown
---
|
|
name: FirstOrEmpty
|
|
slug: firstorempty
|
|
sourceRef: find.go#L567
|
|
category: core
|
|
subCategory: find
|
|
playUrl: https://go.dev/play/p/i200n9wgrDA
|
|
variantHelpers:
|
|
- core#find#firstorempty
|
|
similarHelpers:
|
|
- core#find#first
|
|
- core#find#firstor
|
|
- core#find#lastorempty
|
|
- core#find#nthorempty
|
|
position: 270
|
|
signatures:
|
|
- "func FirstOrEmpty[T any](collection []T) T"
|
|
---
|
|
|
|
Returns the first element of a collection or the zero value if empty.
|
|
|
|
```go
|
|
v := lo.FirstOrEmpty([]int{})
|
|
// v == 0
|
|
```
|
|
|
|
|