Repository: elliotchance/pie (go)

Issue:
Add First()
Is it possible with pie v2 to add `First[T any](ss []T)`?

```go
// First returns the first element or a zero value if there are no
// elements.
func First[T any](ss []T) T {
	if len(ss) == 0 {
		var zeroValue T

		return zeroValue
	}

	return ss[0]
}
```



Pull request description:
Added First(), Last() and fixes issue #181
please find the code in order to fix #181

Patch:
diff --git a/v2/first.go b/v2/first.go
new file mode 100644
index 0000000..6f15b6f
--- /dev/null
+++ b/v2/first.go
@@ -0,0 +1,12 @@
+package pie
+
+// First returns the first element or a zero value if there are no elements.
+func First[T any](ss []T) T {
+	if len(ss) == 0 {
+		var zeroValue T
+
+		return zeroValue
+	}
+
+	return ss[0]
+}
diff --git a/v2/last.go b/v2/last.go
new file mode 100644
index 0000000..0f05c80
--- /dev/null
+++ b/v2/last.go
@@ -0,0 +1,12 @@
+package pie
+
+// Last returns the last element or a zero value if there are no elements.
+func Last[T any](ss []T) T {
+	if len(ss) == 0 {
+		var zeroValue T
+
+		return zeroValue
+	}
+
+	return ss[len(ss)-1]
+}


Test patch:
diff --git a/v2/first_or_test.go b/v2/first_or_test.go
index 5741ec7..acdf2a3 100644
--- a/v2/first_or_test.go
+++ b/v2/first_or_test.go
@@ -6,7 +6,7 @@ import (
 	"testing"
 )
 
-var firstAndLastTests = []struct {
+var firstOrAndLastOrTests = []struct {
 	ss      []float64
 	firstOr float64
 	lastOr  float64
@@ -34,7 +34,7 @@ var firstAndLastTests = []struct {
 }
 
 func TestFirstOr(t *testing.T) {
-	for _, test := range firstAndLastTests {
+	for _, test := range firstOrAndLastOrTests {
 		t.Run("", func(t *testing.T) {
 			assert.Equal(t, test.firstOr, pie.FirstOr(test.ss, 102))
 		})
diff --git a/v2/first_test.go b/v2/first_test.go
new file mode 100644
index 0000000..fbd4257
--- /dev/null
+++ b/v2/first_test.go
@@ -0,0 +1,42 @@
+package pie_test
+
+import (
+	"github.com/elliotchance/pie/v2"
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+var firstAndLastTests = []struct {
+	ss    []float64
+	first float64
+	last  float64
+}{
+	{
+		nil,
+		0,
+		0,
+	},
+	{
+		[]float64{100},
+		100,
+		100,
+	},
+	{
+		[]float64{1, 2},
+		1,
+		2,
+	},
+	{
+		[]float64{1, 2, 3},
+		1,
+		3,
+	},
+}
+
+func TestFirst(t *testing.T) {
+	for _, test := range firstAndLastTests {
+		t.Run("", func(t *testing.T) {
+			assert.Equal(t, test.first, pie.First(test.ss))
+		})
+	}
+}
diff --git a/v2/last_or_test.go b/v2/last_or_test.go
index 86da448..f1f4003 100644
--- a/v2/last_or_test.go
+++ b/v2/last_or_test.go
@@ -7,7 +7,7 @@ import (
 )
 
 func TestLastOr(t *testing.T) {
-	for _, test := range firstAndLastTests {
+	for _, test := range firstOrAndLastOrTests {
 		t.Run("", func(t *testing.T) {
 			assert.Equal(t, test.lastOr, pie.LastOr(test.ss, 202))
 		})
diff --git a/v2/last_test.go b/v2/last_test.go
new file mode 100644
index 0000000..9d14ec1
--- /dev/null
+++ b/v2/last_test.go
@@ -0,0 +1,15 @@
+package pie_test
+
+import (
+	"github.com/elliotchance/pie/v2"
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func TestLast(t *testing.T) {
+	for _, test := range firstAndLastTests {
+		t.Run("", func(t *testing.T) {
+			assert.Equal(t, test.last, pie.Last(test.ss))
+		})
+	}
+}