Coverage Summary for Class: TermOrderKt (it.unibo.tuprolog.argumentation.core.primitives.utils)

Class Class, % Method, % Branch, % Line, % Instruction, %
TermOrderKt 100% (1/1) 100% (3/3) 100% (6/6) 100% (6/6) 100% (59/59)


 package it.unibo.tuprolog.argumentation.core.primitives.utils
 
 import it.unibo.tuprolog.argumentation.core.runtime.Arg2pUnificator
 import it.unibo.tuprolog.core.List
 import it.unibo.tuprolog.core.Substitution
 import it.unibo.tuprolog.core.Term
 import it.unibo.tuprolog.core.TermComparator
 
 internal fun unifyWith(
     target: Term,
     result: Term,
 ): Sequence<Substitution> = Arg2pUnificator.mgu(target, result).let { if (it.isSuccess) sequenceOf(it) else emptySequence() }
 
 internal fun List.sortedTerms(): kotlin.collections.List<Term> = toList().sortedWith(TermComparator.DefaultComparator)
 
 // Standard order of terms, duplicates removed, and variables renamed apart as in setof/3
 internal fun List.distinctSortedTerms(): kotlin.collections.List<Term> =
     sortedTerms()
         .fold(mutableListOf<Term>()) { acc, term ->
             acc.also { if (it.isEmpty() || TermComparator.DefaultComparator.compare(it.last(), term) != 0) it.add(term) }
         }.map { it.freshCopy() }