From 1e785d632cd6523c2d9f308c80d7e2c913b40efb Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Mon, 25 Sep 2023 15:44:31 +0200 Subject: [PATCH] refactor: rename PointerOrNil to ToPointer in order to match other helper names --- README.md | 2 +- option.go | 6 +++--- option_example_test.go | 8 ++++---- option_test.go | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ecc6197..b7984a5 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/option.go b/option.go index 61862be..5044df9 100644 --- a/option.go +++ b/option.go @@ -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 } diff --git a/option_example_test.go b/option_example_test.go index 95a7d85..956243e 100644 --- a/option_example_test.go +++ b/option_example_test.go @@ -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: diff --git a/option_test.go b/option_test.go index d4b1f75..2ecf43f 100644 --- a/option_test.go +++ b/option_test.go @@ -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) {