diff --git a/README.md b/README.md index 4ef4521..cd4a286 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Or, if you need to chain multiple operations you can use one of: - [`pie.OfOrdered`](https://pkg.go.dev/github.com/elliotchance/pie/v2#OfOrdered) - only works with numbers and strings, but has more functions. - [`pie.OfNumeric`](https://pkg.go.dev/github.com/elliotchance/pie/v2#OfNumeric) - only works with numbers, but has all functions. -[Run this program](https://go.dev/play/p/cDLBYzKJ9ld) +[Run this program](https://go.dev/play/p/4IhVbw0koxg) ```go package main @@ -67,7 +67,7 @@ func main() { return strings.HasPrefix(name, "J") }). Map(strings.ToUpper). - LastOr("") + Last() fmt.Println(name) // "SALLY" } diff --git a/v2/of.go b/v2/of.go index b44b106..c9b2ef6 100644 --- a/v2/of.go +++ b/v2/of.go @@ -49,6 +49,10 @@ func (o OfSlice[T]) FindFirstUsing(fn func(value T) bool) int { return FindFirstUsing(o.Result, fn) } +func (o OfSlice[T]) First() T { + return First(o.Result) +} + func (o OfSlice[T]) FirstOr(defaultValue T) T { return FirstOr(o.Result, defaultValue) } @@ -57,6 +61,10 @@ func (o OfSlice[T]) Insert(index int, values ...T) OfSlice[T] { return OfSlice[T]{Insert(o.Result, index, values...)} } +func (o OfSlice[T]) Last() T { + return Last(o.Result) +} + func (o OfSlice[T]) LastOr(defaultValue T) T { return LastOr(o.Result, defaultValue) } diff --git a/v2/of_numeric.go b/v2/of_numeric.go index d314866..0a9b4fc 100644 --- a/v2/of_numeric.go +++ b/v2/of_numeric.go @@ -80,6 +80,10 @@ func (o OfNumericSlice[T]) FindFirstUsing(fn func(value T) bool) int { return FindFirstUsing(o.Result, fn) } +func (o OfNumericSlice[T]) First() T { + return First(o.Result) +} + func (o OfNumericSlice[T]) FirstOr(defaultValue T) T { return FirstOr(o.Result, defaultValue) } @@ -124,6 +128,10 @@ func (o OfNumericSlice[T]) JSONStringIndent(prefix, indent string) string { return JSONStringIndent(o.Result, prefix, indent) } +func (o OfNumericSlice[T]) Last() T { + return Last(o.Result) +} + func (o OfNumericSlice[T]) LastOr(defaultValue T) T { return LastOr(o.Result, defaultValue) } diff --git a/v2/of_ordered.go b/v2/of_ordered.go index 5d20fb3..3baa7c0 100644 --- a/v2/of_ordered.go +++ b/v2/of_ordered.go @@ -76,6 +76,10 @@ func (o OfOrderedSlice[T]) FindFirstUsing(fn func(value T) bool) int { return FindFirstUsing(o.Result, fn) } +func (o OfOrderedSlice[T]) First() T { + return First(o.Result) +} + func (o OfOrderedSlice[T]) FirstOr(defaultValue T) T { return FirstOr(o.Result, defaultValue) } @@ -120,6 +124,10 @@ func (o OfOrderedSlice[T]) JSONStringIndent(prefix, indent string) string { return JSONStringIndent(o.Result, prefix, indent) } +func (o OfOrderedSlice[T]) Last() T { + return Last(o.Result) +} + func (o OfOrderedSlice[T]) LastOr(defaultValue T) T { return LastOr(o.Result, defaultValue) }