Skip to content

Commit

Permalink
doc: typo
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Oct 2, 2022
1 parent 6c6da2c commit e318a1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

@samber: I sometimes forget to update this file. Ping me on [Twitter](https://twitter.com/samuelberthe) or open an issue in case of error. We need to keep a clear changelog for easier lib upgrade.

## 1.x.y (2022-xx-yy)

Adding:

- lo.TernaryF

## 1.29.0 (2022-10-02)

Adding:
Expand Down
9 changes: 7 additions & 2 deletions README.md
Expand Up @@ -176,7 +176,8 @@ Supported search helpers:

Conditional helpers:

- [Ternary (1 line if/else statement)](#ternary)
- [Ternary](#ternary)
- [TernaryF](#ternaryf)
- [If / ElseIf / Else](#if--elseif--else)
- [Switch / Case / Default](#switch--case--default)

Expand Down Expand Up @@ -1550,6 +1551,8 @@ result := lo.Ternary[string](false, "a", "b")

### TernaryF

A 1 line if/else statement whose options are functions.

```go
result := lo.TernaryF[string](true, func() string { return "a" }, func() string { return "b" })
// "a"
Expand All @@ -1562,7 +1565,9 @@ Useful to avoid nil-pointer dereferencing in intializations, or avoid running un

```go
var s *string
someStr := TernaryF[string](s.Val == nil, func() string { return uuid.New().String() }, func() string { return *s })

someStr := TernaryF[string](s == nil, func() string { return uuid.New().String() }, func() string { return *s })
// ef782193-c30c-4e2e-a7ae-f8ab5e125e02
```

### If / ElseIf / Else
Expand Down
1 change: 1 addition & 0 deletions condition.go
Expand Up @@ -14,6 +14,7 @@ func TernaryF[T any](condition bool, ifFunc func() T, elseFunc func() T) T {
if condition {
return ifFunc()
}

return elseFunc()
}

Expand Down

0 comments on commit e318a1f

Please sign in to comment.