func (q Query) distinct(f func(T, T) (bool, error)) (r Query) {
	if q.err != nil {
		r.err = q.err
		return r
	}

	if f == nil {
		// basic equality comparison using dict
		dict := make(map[T]bool)
		for _, v := range q.values {
			if _, ok := dict[v]; !ok {
				dict[v] = true
			}
		}
		res := make([]T, len(dict))
		i := 0
		for key := range dict {
			res[i] = key
			i++
		}
		r.values = res
	} else {
		// use equality comparer and bool flags for each item
		// here we check all a[i]==a[j] i<j, practically worst case
		// for this is O(N^2) where all elements are different and best case
		// is O(N) where all elements are the same
		// pick lefthand side value of the comparison in the result
		l := len(q.values)
		results := make([]T, 0)
		included := make([]bool, l)
		for i := 0; i < l; i++ {
			if included[i] {
				continue
			}
			for j := i + 1; j < l; j++ {
				equals, err := f(q.values[i], q.values[j])
				if err != nil {
					r.err = err
					return
				}
				if equals {
					included[j] = true // don't include righthand side value
				}
			}
			results = append(results, q.values[i])
		}
		r.values = results
	}
	return
}
// distinct returns distinct elements from the provided source using default
// equality comparer (==) or a custom equality comparer function. Complexity
// is O(N).
distinct returns distinct elements from the provided source using default
equality comparer (==) or a custom equality comparer function. Complexity
is O(N).
// distinct returns distinct elements from the provided source using default // equality comparer ( == ) or a custom equality comparer function . Complexity // is O ( N ) .
func (q Query) distinct(f func(T, T) (bool, error)) (r Query) {
	if q.err != nil {
		r.err = q.err
		return r
	}
	if f == nil {
		dict := make(map[T]bool)
		for _, v := range q.values {
			if _, ok := dict[v]; !ok {
				dict[v] = true
			}
		}
		res := make([]T, len(dict))
		i := 0
		for key := range dict {
			res[i] = key
			i++
		}
		r.values = res
	} else {
		l := len(q.values)
		results := make([]T, 0)
		included := make([]bool, l)
		for i := 0; i < l; i++ {
			if included[i] {
				continue
			}
			for j := i + 1; j < l; j++ {
				equals, err := f(q.values[i], q.values[j])
				if err != nil {
					r.err = err
					return
				}
				if equals {
					included[j] = true 
				}
			}
			results = append(results, q.values[i])
		}
		r.values = results
	}
	return
}
func ( q Query ) distinct ( f func ( T , T ) ( bool , error ) ) ( r Query ) { if q . err != nil { r . err = q . err return r } if f == nil { dict := make ( map [ T ] bool ) for _ , v := range q . values { if _ , ok := dict [ v ] ; ! ok { dict [ v ] = true } } res := make ( [ ] T , len ( dict ) ) i := 0 for key := range dict { res [ i ] = key i ++ } r . values = res } else { l := len ( q . values ) results := make ( [ ] T , 0 ) included := make ( [ ] bool , l ) for i := 0 ; i < l ; i ++ { if included [ i ] { continue } for j := i + 1 ; j < l ; j ++ { equals , err := f ( q . values [ i ] , q . values [ j ] ) if err != nil { r . err = err return } if equals { included [ j ] = true } } results = append ( results , q . values [ i ] ) } r . values = results } return }
distinct returns distinct elements from the provided source using default
equality comparer (==) or a custom equality comparer function.
distinct returns distinct elements from the provided source using default equality comparer ( == ) or a custom equality comparer function .
// basic equality comparison using dict // use equality comparer and bool flags for each item // here we check all a[i]==a[j] i<j, practically worst case // for this is O(N^2) where all elements are different and best case // is O(N) where all elements are the same // pick lefthand side value of the comparison in the result // don't include righthand side value