Files
lo/docs/data/core-firstor.md
T
Samuel Berthe fa095e4b4f fix(doc): fix go playground demo URL (#832)
* fix(doc): fix go playground demo URL

* fix(doc): add more go playground demo URL
2026-03-06 00:09:59 +01:00

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
```