<commit_before>// common slice operations
package cores

import (
	"fmt"
	"reflect"
)

func IsContainer(slice interface{}) bool {
	typ := reflect.TypeOf(slice)
	k := typ.Kind()
	switch k {
	case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String:
		return true
	default:
		return false
	}
}
func Empty(slice interface{}) (bool, error) {
	if IsContainer(slice) {
		return reflect.ValueOf(slice).Len() != 0, nil
	} else {
		return false, fmt.Errorf("Provided thing is not a slice, it is a %t", reflect.TypeOf(slice).Kind().String())
	}
}<commit_msg>Added some other common functions<commit_after>// common slice operations
package cores

import (
	"fmt"
	"reflect"
)

func IsContainer(slice interface{}) bool {
	typ := reflect.TypeOf(slice)
	k := typ.Kind()
	switch k {
	case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String:
		return true
	default:
		return false
	}
}
func Empty(slice interface{}) (bool, error) {
	if IsContainer(slice) {
		return reflect.ValueOf(slice).Len() != 0, nil
	} else {
		return false, fmt.Errorf("Provided thing is not a container, it is a %t", reflect.TypeOf(slice))
	}
}

func First(slice interface{}) (interface{}, error) {
	switch reflect.TypeOf(slice).Kind() {
	case reflect.String, reflect.Array, reflect.Slice:
		val := reflect.ValueOf(slice)
		if val.Len() > 0 {
			return val.Index(0), nil
		} else {
			return nil, nil
		}
	default:
		return nil, fmt.Errorf("Provided thing is not a sliceable thing, it is a %t", reflect.TypeOf(slice))
	}
}
func Rest(slice interface{}) (interface{}, error) {
	switch reflect.TypeOf(slice).Kind() {
	case reflect.String, reflect.Array, reflect.Slice:
		val := reflect.ValueOf(slice)
		if val.Len() > 0 {
			return val.Slice(1, val.Len()), nil
		} else {
			return nil, nil
		}
	default:
		return nil, fmt.Errorf("Provided thing is not a sliceable thing, it is a %t", reflect.TypeOf(slice))
	}
}
{'fraction_non_alphanumeric': 0.143530644316396, 'fraction_numerical': 0.003143006809848088, 'mean_word_length': 4.134408602150538, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '387765', 'n_tokens_mistral': 672, 'n_tokens_neox': 634, 'n_words': 191}