Skip to content

Commit

Permalink
doc: adding documentation for iff/elseiff/elsef
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Apr 12, 2022
1 parent d5bc961 commit 6e8b0c2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,31 @@ result := lo.If[int](false, 1).
// 3
```

Using callbacks:

```go
result := lo.IfF[int](true, func () int {
return 1
}).
ElseIfF(false, func () int {
return 2
}).
ElseF(func () int {
return 3
})
// 1
```

Mixed:

```go
result := lo.IfF[int](true, func () int {
return 1
}).
Else(42)
// 1
```

### Switch / Case / Default

```go
Expand Down Expand Up @@ -986,6 +1011,17 @@ result := lo.Switch[int, string](1).
// "1"
```

Mixed:

```go
result := lo.Switch[int, string](1).
CaseF(1, func() string {
return "1"
}).
Default("42")
// "42"
```

### ToPtr

Returns a pointer copy of value.
Expand Down

0 comments on commit 6e8b0c2

Please sign in to comment.