<commit_before>// Copyright 2015, <NAME>
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package attr

// Getter is an interface which is implemented by types which want to export typed
// values.
type Getter interface {
	GetInt(string) int
	GetString(string) string
	GetStrings(string) []string
}

// Interface is a type which defines behaviour necessary to implement a typed attribute.
type Interface interface {
	Field() string
	IsEmpty(x interface{}) bool
	Value(Getter) interface{}
	Intersect(x, y interface{}) interface{}
}

type valueType struct {
	field string
	empty interface{}
	get   func(Getter) interface{}
}

func (v *valueType) Field() string {
	return v.field
}

func (v *valueType) IsEmpty(x interface{}) bool {
	return v.empty == x
}

func (v *valueType) Value(g Getter) interface{} {
	return v.get(g)
}

func (v *valueType) Intersect(x, y interface{}) interface{} {
	if x == y {
		return x
	}
	return v.empty
}

func String(f string) Interface {
	return &valueType{
		field: f,
		empty: "",
		get: func(g Getter) interface{} {
			return g.GetString(f)
		},
	}
}

func Int(f string) Interface {
	return &valueType{
		field: f,
		empty: 0,
		get: func(g Getter) interface{} {
			return g.GetInt(f)
		},
	}
}

type stringsType struct {
	valueType
}

func (p *stringsType) IsEmpty(x interface{}) bool {
	if x == nil {
		return true
	}
	xs := x.([]string)
	return len(xs) == 0
}

func (p *stringsType) Intersect(x, y interface{}) interface{} {
	if x == nil || y == nil {
		return nil
	}
	xs := x.([]string)
	ys := y.([]string)
	return stringSliceIntersect(xs, ys)
}

func Strings(f string) Interface {
	return &stringsType{
		valueType{
			field: f,
			empty: nil,
			get: func(g Getter) interface{} {
				return g.GetStrings(f)<commit_msg>Added godoc to attr.<commit_after>// Copyright 2015, <NAME>
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package attr defines types and helpers for accessing typed attributes.
package attr

// Getter is an interface which is implemented by types which want to export typed
// values.
type Getter interface {
	GetInt(string) int
	GetString(string) string
	GetStrings(string) []string
}

// Interface is a type which defines behaviour necessary to implement a typed attribute.
type Interface interface {
	// Field returns the name of the attribute.
	Field() string

	// IsEmpty returns true iff `x` is a representation of the empty value of this attribute.
	IsEmpty(x interface{}) bool

	// Value returns the value of this attribute in `g`.
	Value(g Getter) interface{}

	// Intersect returns the intersection of `x` and `y`, assumed to be the type of the
	// attribute.
	Intersect(x, y interface{}) interface{}
}

type valueType struct {
	field string
	empty interface{}
	get   func(Getter) interface{}
}

func (v *valueType) Field() string {
	return v.field
}

func (v *valueType) IsEmpty(x interface{}) bool {
	return v.empty == x
}

func (v *valueType) Value(g Getter) interface{} {
	return v.get(g)
}

func (v *valueType) Intersect(x, y interface{}) interface{} {
	if x == y {
		return x
	}
	return v.empty
}

// String constructs an implementation of Interface with the field name `f` to access a string
// attribute of an implementation of Getter.
func String(f string) Interface {
	return &valueType{
		field: f,
		empty: "",
		get: func(g Getter) interface{} {
			return g.GetString(f)
		},
	}
}

// Int constructs an implementation of Interface with the field name `f` to access an int
// attribute of an implementation of Getter.
func Int(f string) Interface {
	return &valueType{
		field: f,
		empty: 0,
		get: func(g Getter) interface{} {
			return g.GetInt(f)
		},
	}
}

type stringsType struct {
	valueType
}

func (p *stringsType) IsEmpty(x interface{}) bool {
	if x == nil {
		return true
	}
	xs := x.([]string)
	return len(xs) == 0
}

func (p *stringsType) Intersect(x, y interface{}) interface{} {
	if x == nil || y == nil {
		return nil
	}
	xs := x.([]string)
	ys := y.([]string)
	return stringSliceIntersect(xs, ys)
}

// Strings constructs an implementation of Interface with the field name `f` to access a string slice
// attribute of an implementation of Getter.
func Strings(f string) Interface {
	return &stringsType{
		valueType{
			field: f,
			empty: nil,
			get: func(g Getter) interface{} {
				return g.GetStrings(f)
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.0027149321266968325, 'mean_word_length': 3.6882290562036055, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7442413', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1420, 'n_words': 550}