Skip to content

Commit

Permalink
Merge pull request mattn#10 from srt180/main
Browse files Browse the repository at this point in the history
Use generic type instead of interface{}
  • Loading branch information
mattn authored Dec 31, 2021
2 parents 86a53ec + a3fffd6 commit cb729fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion list/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (l *List[T]) Push(v T) {
}

func (l *List[T]) Insert(v T) {
l.l, l.l[0] = append(l.l[:1], l.l[0:]...), v
l.InsertAt(0, v)
return
}

Expand Down
8 changes: 2 additions & 6 deletions reduce/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
)

func reduceFunc[T any](a []T, f func(T, T) T, initial interface{}) T {
func reduceFunc[T any](a []T, f func(T, T) T, initial T) T {
if len(a) == 0 || f == nil {
var vv T
return vv
Expand All @@ -24,11 +24,7 @@ func reduceFunc[T any](a []T, f func(T, T) T, initial interface{}) T {
return result
}

if initial == nil {
return reduce(a, f, a[0], 1, 1, l-1)
}

return reduce(a, f, initial.(T), 0, 1, l)
return reduce(a, f, initial, 0, 1, l)
}

func main() {
Expand Down

0 comments on commit cb729fd

Please sign in to comment.