doc: adding isnil

This commit is contained in:
Samuel Berthe
2023-12-02 14:53:23 +01:00
committed by GitHub
parent 2bbb3ea5f7
commit 3283fe13ea

View File

@@ -216,6 +216,7 @@ Conditional helpers:
Type manipulation helpers:
- [IsNil](#IsNil)
- [ToPtr](#toptr)
- [EmptyableToPtr](#emptyabletoptr)
- [FromPtr](#fromptr)
@@ -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")