// FindOne will a single message where all
// filters return true. If more than one
// message matches return ErrTooManyResults.
// If no messages match all filters we will
// return ErrNotFound.
FindOne will a single message where all
filters return true. If more than one
message matches return ErrTooManyResults.
If no messages match all filters we will
return ErrNotFound.
// FindOne will a single message where all // filters return true . If more than one // message matches return ErrTooManyResults . // If no messages match all filters we will // return ErrNotFound .
func (messages Messages) FindOne(filters ...Filter) (proto.Message, error) {
	var (
		position int
		match    bool
	)
loop:
	for i, message := range messages {
		for _, filter := range filters {
			if !filter(message) {
				continue loop
			}
		}
		if match {
			return nil, ErrTooManyResults
		}
		match = true
		position = i
	}
	if !match {
		return nil, ErrNotFound
	}
	return messages[position], nil
}
func ( messages Messages ) FindOne ( filters ... Filter ) ( proto . Message , error ) { var ( position int match bool ) loop : for i , message := range messages { for _ , filter := range filters { if ! filter ( message ) { continue loop } } if match { return nil , ErrTooManyResults } match = true position = i } if ! match { return nil , ErrNotFound } return messages [ position ] , nil }
FindOne will a single message where all
filters return true.
FindOne will a single message where all filters return true .
// Already matched a message // Mark this message as matched