superquants.render.ComplexSuffixPrinter.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of superquants_sjs0.6_2.12 Show documentation
Show all versions of superquants_sjs0.6_2.12 Show documentation
Scala: Typelevel unboxed compile time dimensional analysis over tagged types. Intellij Idea compatible 100%
The newest version!
package superquants.render
import shapeless.{::, HList, HNil}
import superquants.SuffixPrinter
trait ComplexSuffixPrinter[H <: HList, Raw] {
def notNil: Boolean
def apply(printNumerator: Boolean): String
}
object ComplexSuffixPrinter {
implicit def prettySuffixForNothing[Raw]: ComplexSuffixPrinter[Nothing :: HNil, Raw] = new ComplexSuffixPrinter[Nothing :: HNil, Raw] {
def notNil = false
def apply(printNumerator: Boolean): String = ???
}
implicit def prettySuffixForNil[Raw]: ComplexSuffixPrinter[HNil, Raw] = new ComplexSuffixPrinter[HNil, Raw] {
def notNil = false
def apply(printNumerator: Boolean): String = ???
}
implicit def prettySuffixRecur[Raw, T, Tail <: HList](implicit tail: ComplexSuffixPrinter[Tail, Raw], suffix: SuffixPrinter[T], znak: ExPowZnak[T]): ComplexSuffixPrinter[T :: Tail, Raw] = new ComplexSuffixPrinter[T :: Tail, Raw] {
def notNil = true
def apply(printNumerator: Boolean): String = {
if (
(printNumerator && znak.isNumerator) ||
(!printNumerator && !znak.isNumerator)
) {
if (tail.notNil) {
val t = tail(printNumerator).trim
if (t.isEmpty) {
s"${suffix()}"
} else {
s"${suffix()} * ${t}"
}
} else {
s"${suffix()}"
}
} else {
if (tail.notNil) {
s"${tail(printNumerator)}"
} else {
""
}
}
}
}
}