package log

// Fields is a linked list of (name, value) couple
type Fields struct {
	name     string
	value    interface{}
	previous *Fields
}

// With creates new Fields that include the given (name, value) couple.
func (f *Fields) With(name string, value interface{}) *Fields {
	return &Fields{name, value, f}
}

// ForEach applies the given function for each (name, value) couple, as long as it returns true.
func (f *Fields) ForEach(do func(string, interface{}) bool) {
	for i := f; i != nil && do(i.name, i.value); i = i.previous {
	}
}

func (f *Fields) IsEmpty() bool {
	return f == nil
}