Skip to content

Instantly share code, notes, and snippets.

View harrison3000's full-sized avatar

Harrison harrison3000

View GitHub Profile
@harrison3000
harrison3000 / arena.go
Created May 15, 2022 13:06
Trivial generic arena alocator for go
package arena
func ArenaAlloc[T any](n int) <-chan *T {
c := make(chan *T, n/2)
go func() {
for {
s := make([]T, n)
for k := range s {
c <- &s[k]
@harrison3000
harrison3000 / slicefilter.go
Created May 14, 2022 12:44
Simple generic slice filtering function for Golang 1.18+
package slicefilter
// FilterSliceFunc filters the input slice based on a pass function
// and returns the filtered slice
// it filters inplace and modifies the input slice, so be careful!
func FilterSliceFunc[S any](in []S, pass func(S) bool) []S {
outIdx := 0
for _, v := range in {
if !pass(v) {
continue