Skip to content

Commit 17d82f4

Browse files
fix: Issue 605 (README for Ternary() (#606)
* fix: Issue 605 * Add the Ternary comment from prev commit to function docstring
1 parent b828ea1 commit 17d82f4

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,7 @@ lo.SamplesBy([]string{"a", "b", "c"}, 3, r.Intn)
28532853

28542854
A 1 line if/else statement.
28552855

2856+
28562857
```go
28572858
result := lo.Ternary(true, "a", "b")
28582859
// "a"
@@ -2861,6 +2862,8 @@ result := lo.Ternary(false, "a", "b")
28612862
// "b"
28622863
```
28632864

2865+
Take care to avoid dereferencing potentially nil pointers in your A/B expressions, because they are both evaluated. See TernaryF to avoid this problem.
2866+
28642867
[[play](https://go.dev/play/p/t-D7WBL44h2)]
28652868

28662869
### TernaryF

condition.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lo
22

33
// Ternary is a 1 line if/else statement.
4+
// Take care to avoid dereferencing potentially nil pointers in your A/B expressions, because they are both evaluated. See TernaryF to avoid this problem.
45
// Play: https://go.dev/play/p/t-D7WBL44h2
56
func Ternary[T any](condition bool, ifOutput T, elseOutput T) T {
67
if condition {

0 commit comments

Comments
 (0)