Skip to content

Commit

Permalink
doc: adding isnil
Browse files Browse the repository at this point in the history
  • Loading branch information
samber authored Dec 2, 2023
1 parent 2bbb3ea commit 3283fe1
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Conditional helpers:

Type manipulation helpers:

- [IsNil](#IsNil)
- [ToPtr](#toptr)
- [EmptyableToPtr](#emptyabletoptr)
- [FromPtr](#fromptr)
Expand Down Expand Up @@ -2155,9 +2156,33 @@ result := lo.Switch(1).

[[play](https://go.dev/play/p/TGbKUMAeRUd)]

### IsNil

Checks if a value is nil or if it's a reference type with a nil underlying value.

```go
var x int
IsNil(x))
// false

var k struct{}
IsNil(k)
// false

var i *int
IsNil(i)
// true

var ifaceWithNilValue any = (*string)(nil)
IsNil(ifaceWithNilValue)
// true
ifaceWithNilValue == nil
// false
```

### ToPtr

Returns a pointer copy of value.
Returns a pointer copy of the value.

```go
ptr := lo.ToPtr("hello world")
Expand Down

0 comments on commit 3283fe1

Please sign in to comment.