<commit_before>package un

import (
	"fmt"
	"reflect"
	"sync"
)

func init() {
	fmt.Println("")
	MakeEach(&Each)
	MakeEach(&EachInt)
}

// Each func(func(A), []A)
// Applies the given function to each item of a slice or map
// Note: unlike map, each does not return a collection
var Each func(func(interface{}), interface{})

// EachInt on a slice of ints
var EachInt func(func(int), []int)

// MakeEach implements a typed Each function in the form Each func(func(A), []A)
func MakeEach(fn interface{}) {
	Maker(fn, _each)
}

func _each(values []reflect.Value) []reflect.Value {
	fn := values[0]

	v := iToValue(values[1])

	for i := 0; i < v.Len(); i++ {
		e := v.Index(i)
		fn.Call([]reflect.Value{e})
	}

	return nil
}

func _pEach(values []reflect.Value) []reflect.Value {
	// var done sync.WaitGroup

	fn := values[0]

	v := iToValue(values[1])

	for i := 0; i < v.Len(); i++ {
		e := v.Index(i)
		fn.Call([]reflect.Value{e})
	}

	return nil
}

// Reference Each Implementation
func RefEach(slice []string, fn func(string)) {
	for i := 0; i < len(slice); i++ {
		fn(slice[i])
	}
}

// Reference Parallel Each Implementation
func RefPEach(slice []string, fn func(string)) {
	var done sync.WaitGroup

	l := len(slice)

	// sem := make(semaphore, l)
	// close(sem)

	for i := 0; i < l; i++ {
		s := slice[i]
		done.Add(1)
		go func() {
			fn(s)
			done.Done()
		}()
	}

	done.Wait()
}

// type empty {}
// ...
// data := make([]float, N);
// res := make([]float, N);<commit_msg>use range in PEach<commit_after>package un

import (
	"fmt"
	"reflect"
	"sync"
)

func init() {
	fmt.Println("")
	MakeEach(&Each)
	MakeEach(&EachInt)
}

// Each func(func(A), []A)
// Applies the given function to each item of a slice or map
// Note: unlike map, each does not return a collection
var Each func(func(interface{}), interface{})

// EachInt on a slice of ints
var EachInt func(func(int), []int)

// MakeEach implements a typed Each function in the form Each func(func(A), []A)
func MakeEach(fn interface{}) {
	Maker(fn, _each)
}

func _each(values []reflect.Value) []reflect.Value {
	fn := values[0]

	v := iToValue(values[1])

	for i := 0; i < v.Len(); i++ {
		e := v.Index(i)
		fn.Call([]reflect.Value{e})
	}

	return nil
}

func _pEach(values []reflect.Value) []reflect.Value {
	// var done sync.WaitGroup

	fn := values[0]

	v := iToValue(values[1])

	for i := 0; i < v.Len(); i++ {
		e := v.Index(i)
		fn.Call([]reflect.Value{e})
	}

	return nil
}

// Reference Each Implementation
func RefEach(slice []string, fn func(string)) {
	for i := 0; i < len(slice); i++ {
		fn(slice[i])
	}
}

// Reference Parallel Each Implementation
func RefPEach(slice []string, fn func(string)) {
	var done sync.WaitGroup
	for _, s := range slice {
		s := s
		done.Add(1)
		go func() {
			fn(s)
			done.Done()
		}()
	}

	done.Wait()
}

// type empty {}
// ...
// data := make([]float, N);
// res := make([]float, N);
{'fraction_non_alphanumeric': 0.1876295784381479, 'fraction_numerical': 0.005874222529371113, 'mean_word_length': 3.3599397590361444, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3148120', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1095, 'n_words': 318}