Skip to content

Commit

Permalink
Shift to accept any parameter (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
SlothNinja authored Sep 7, 2023
1 parent fc03ccc commit f1ace5f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions v2/shift.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pie

import "golang.org/x/exp/constraints"

// Shift will return two values: the shifted value and the rest slice.
func Shift[T constraints.Integer | constraints.Float](ss []T) (T, []T) {
return FirstOr(ss, 0), DropTop(ss, 1)
// if the slice is empty then returned shifted value is the zero value of the slice elements and the rest slice is empty slice
func Shift[T any](ss []T) (T, []T) {
var zeroValue T
return FirstOr(ss, zeroValue), DropTop(ss, 1)
}

0 comments on commit f1ace5f

Please sign in to comment.