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
488 B
Markdown
28 lines
488 B
Markdown
---
|
|
name: FirstOr
|
|
slug: firstor
|
|
sourceRef: find.go#L574
|
|
category: core
|
|
subCategory: find
|
|
playUrl: https://go.dev/play/p/x9CxQyRFXeZ
|
|
variantHelpers:
|
|
- core#find#firstor
|
|
similarHelpers:
|
|
- core#find#first
|
|
- core#find#firstorempty
|
|
- core#find#lastor
|
|
- core#find#nthor
|
|
position: 280
|
|
signatures:
|
|
- "func FirstOr[T any](collection []T, fallback T) T"
|
|
---
|
|
|
|
Returns the first element of a collection or the fallback value if empty.
|
|
|
|
```go
|
|
v := lo.FirstOr([]int{}, -1)
|
|
// v == -1
|
|
```
|
|
|
|
|