All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.decomat.Is.kt Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package io.decomat

class Is private constructor (private val type: Typed, private val valueCompare: ValueCompare): Pattern0(type) {
  override fun matches(r: ProductClass): Boolean =
    isType(r.value, type.type) &&
      when(valueCompare) {
        is DoCompare -> r.value == valueCompare.value
        is DontCompare -> true
      }

  companion object {
    private sealed interface ValueCompare
    private data class DoCompare(val value: R): ValueCompare
    private object DontCompare: ValueCompare

    fun  TypedAs(type: Typed) = Is(type, DontCompare)
    fun  ValuedAs(type: Typed, value: R) = Is(type, DoCompare(value))
    inline operator fun  invoke(): Is = Is.TypedAs(Typed())
    inline operator fun  invoke(value: R): Is = Is.ValuedAs(Typed(), value)
  }
}

inline fun  IsAny() = Is()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy