<commit_before>package valider

import (
	"reflect"
	"time"
)

type Map struct {
	raw    interface{}
	field  string
	errors *Errors

	value reflect.Value
}

func (v *Validator) Map(value interface{}, field string) *Map {
	return &Map{raw: value, field: field, errors: v.Errors}
}

func (ma *Map) Required() *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	switch ma.value.Kind() {
	case reflect.Map:
		if ma.value.Len() == 0 {
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrRequired, CodeRequired})
		}
	default:
		(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
	}
	return ma
}

func (ma *Map) Keys(keys ...string) *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	if ma.value.Len() != 0 {
		switch ma.value.Kind() {
		case reflect.Map:
			for _, key := range keys {
				if !ma.value.MapIndex(reflect.ValueOf(key)).IsValid() {
					(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrNotFound, CodeNotFound})
				}
			}
		default:
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
		}
	}
	return ma
}

func (ma *Map) Range(min, max int) *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	if ma.value.Len() != 0 {
		switch ma.value.Kind() {
		case reflect.Map:
			len := ma.value.Len()
			if len < min || len > max {
				(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrOutRange, CodeOutRange})
			}
		default:
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
		}
	}
	return ma
}

func (ma *Map) In(values interface{}) *Map {
	return ma
}

func (ma *Map) Date(layout string) *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	if ma.value.Len() != 0 {
		switch ma.value.Kind() {
		case reflect.Map:
			for _, key := range ma.value.MapKeys() {
				ma.value = ma.value.MapIndex(key)
				ma.date(layout)
			}
		default:
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
		}
	}
	return ma
}

func (ma *Map) date(layout string) *Map {
	switch ma.value.Kind() {
	case reflect.Slice, reflect.Array:
		len := ma.value.Len()
		for i := 0; i < len; i++ {
			ma.value = ma.value.Index(i)
			ma.date(layout)
		}
	case reflect.String:
		if _, err := time.Parse(layout, ma.value.String()); err != nil {
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrDate, CodeDate})
		}
	default:
		(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
	}
	return ma
}
<commit_msg>add new functionality for map types<commit_after>package valider

import (
	"reflect"
	"time"
)

type Map struct {
	raw    interface{}
	field  string
	errors *Errors

	value reflect.Value
}

func (v *Validator) Map(value interface{}, field string) *Map {
	return &Map{raw: value, field: field, errors: v.Errors}
}

func (ma *Map) Required() *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	switch ma.value.Kind() {
	case reflect.Map:
		if ma.value.Len() == 0 {
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrRequired, CodeRequired})
		}
	default:
		(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
	}
	return ma
}

func (ma *Map) SameKeys(keys ...string) *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	if ma.value.Len() != 0 {
		switch ma.value.Kind() {
		case reflect.Map:
		for _, key := range keys {
			if !ma.value.MapIndex(reflect.ValueOf(key)).IsValid() {
				(*ma.errors)[ma.field+"."+key] = append((*ma.errors)[ma.field+"."+key], Error{ErrNotFound, CodeNotFound})
			}
		}
		default:
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
		}
	}
	return ma
}

func (ma *Map) Keys(keys ...string) *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	if ma.value.Len() != 0 {
		switch ma.value.Kind() {
		case reflect.Map:
			k := ma.value.MapKeys()
			for _, v := range k {
				found := false
				for _, key := range keys {
					if v.String() == key {
						found = true
					}
				}
				if !found {
					(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrNotFound, CodeNotFound})
				}
			}
		default:
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
		}
	}
	return ma
}

func (ma *Map) Range(min, max int) *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	if ma.value.Len() != 0 {
		switch ma.value.Kind() {
		case reflect.Map:
			len := ma.value.Len()
			if len < min || len > max {
				(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrOutRange, CodeOutRange})
			}
		default:
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
		}
	}
	return ma
}

func (ma *Map) In(values interface{}) *Map {
	return ma
}

func (ma *Map) Date(layout string) *Map {
	ma.value = reflect.ValueOf(ma.raw)
	if ma.value.Kind() == reflect.Ptr {
		ma.value = ma.value.Elem()
	}
	if ma.value.Len() != 0 {
		switch ma.value.Kind() {
		case reflect.Map:
			for _, key := range ma.value.MapKeys() {
				ma.value = ma.value.MapIndex(key)
				ma.date(layout)
			}
		default:
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
		}
	}
	return ma
}

func (ma *Map) date(layout string) *Map {
	switch ma.value.Kind() {
	case reflect.Slice, reflect.Array:
		len := ma.value.Len()
		for i := 0; i < len; i++ {
			ma.value = ma.value.Index(i)
			ma.date(layout)
		}
	case reflect.String:
		if _, err := time.Parse(layout, ma.value.String()); err != nil {
			(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrDate, CodeDate})
		}
	default:
		(*ma.errors)[ma.field] = append((*ma.errors)[ma.field], Error{ErrUnsupported, CodeUnsupported})
	}
	return ma
}

{'fraction_non_alphanumeric': 0.18941681233116162, 'fraction_numerical': 0.0017479739392976322, 'mean_word_length': 3.4861012116892374, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3530351', 'n_tokens_mistral': 2581, 'n_tokens_neox': 2403, 'n_words': 495}