Skip to content

Commit

Permalink
refactor: rename PointerOrNil to ToPointer in order to match other he…
Browse files Browse the repository at this point in the history
…lper names
  • Loading branch information
samber committed Sep 25, 2023
1 parent 8ccc38e commit 1e785d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Methods:
- `.MustGet()` [doc](https://pkg.go.dev/github.com/samber/mo#Option.MustGet) - [play](https://go.dev/play/p/RVBckjdi5WR)
- `.OrElse()` [doc](https://pkg.go.dev/github.com/samber/mo#Option.OrElse) - [play](https://go.dev/play/p/TrGByFWCzXS)
- `.OrEmpty()` [doc](https://pkg.go.dev/github.com/samber/mo#Option.OrEmpty) - [play](https://go.dev/play/p/SpSUJcE-tQm)
- `.PointerOrNil()` [doc](https://pkg.go.dev/github.com/samber/mo#Option.PointerOrNil) - [play](https://go.dev/play/p/iRlxc2K8HQL)
- `.ToPointer()` [doc](https://pkg.go.dev/github.com/samber/mo#Option.ToPointer) - [play](https://go.dev/play/p/N43w92SM-Bs)
- `.ForEach()` [doc](https://pkg.go.dev/github.com/samber/mo#Option.ForEach)
- `.Match()` [doc](https://pkg.go.dev/github.com/samber/mo#Option.Match) - [play](https://go.dev/play/p/1V6st3LDJsM)
- `.Map()` [doc](https://pkg.go.dev/github.com/samber/mo#Option.Map) - [play](https://go.dev/play/p/mvfP3pcP_eJ)
Expand Down
6 changes: 3 additions & 3 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ func (o Option[T]) FlatMap(mapper func(value T) Option[T]) Option[T] {
return None[T]()
}

// PointerOrNil returns value if present or a nil pointer.
// Play: https://go.dev/play/p/iRlxc2K8HQL
func (o Option[T]) PointerOrNil() *T {
// ToPointer returns value if present or a nil pointer.
// Play: https://go.dev/play/p/N43w92SM-Bs
func (o Option[T]) ToPointer() *T {
if !o.isPresent {
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions option_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ func ExampleOption_OrEmpty_none() {
// Output: 0
}

func ExampleOption_PointerOrNil_some() {
func ExampleOption_ToPointer_some() {
some := Some(42)
result := some.PointerOrNil()
result := some.ToPointer()

fmt.Println(*result)
// Output: 42
}

func ExampleOption_PointerOrNil_none() {
func ExampleOption_ToPointer_none() {
none := None[int]()
result := none.PointerOrNil()
result := none.ToPointer()

fmt.Println(result)
// Output: <nil>
Expand Down
6 changes: 3 additions & 3 deletions option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ func TestOptionOrEmpty(t *testing.T) {
is.Equal(0, None[int]().OrEmpty())
}

func TestOptionPointerOrNil(t *testing.T) {
func TestOptionToPointer(t *testing.T) {
is := assert.New(t)

p := Some(42).PointerOrNil()
p := Some(42).ToPointer()
is.NotNil(p)
is.Equal(42, *p)

is.Nil(None[int]().PointerOrNil())
is.Nil(None[int]().ToPointer())
}

func TestOptionForEach(t *testing.T) {
Expand Down

0 comments on commit 1e785d6

Please sign in to comment.