         return .variable(".v\(n)", binding: true)
     }
     
-    private func triples(from results: AnyIterator<TermResult>, with template: [TriplePattern]) -> [Triple] {
-        var triples = [Triple]()
+    private func triples<S : Sequence>(from results: S, with template: [TriplePattern]) -> [Triple] where S.Element == TermResult {
+        var triples = Set<Triple>()
         for r in results {
             for tp in template {
                 do {

                        return nil
                    }
                    if let ground = replaced.ground {
                        triples.append(ground)
                    }
                } catch {}
            }
        }
        return triples
    }
    
    public func evaluate(query: Query, activeGraph: Term) throws -> QueryResult<[TermResult], [Triple]> {

        case .select(_):
            return QueryResult.bindings(query.projectedVariables, results)
        case .construct(let template):
            let t = triples(from: results, with: template)
            return QueryResult.triples(t)
        default:
            throw QueryError.evaluationError("TODO: evaluate(query) not implemented for \(query.form)")
