Packages

trait Translator[I, O] extends (I) => Option[O]

Translator from an input I to an output O, designed to be built recursively.

Translation by Splitting and joining

The most import class of translators are constructed from

* a split map I => Option[X], where X is obtained from I by taking Tuples, Lists and sub-types

* a join map Y => Option[O], where Y is obtained from O structurally, in the same way as X is obtained from I, e.g. X = (I, I) and Y = (O, O).

However X and Y may involve taking sub-types independently of each other.

Such a translator splits an input, recursively translates X to Y and combines the result with the join (all steps work optionally).

Combinations, Basic Translators

Translators are built by combining others by OrElse, starting with basic translators specified by a function I => Option[O]. One can instead start with an empty translator.

Note that we can restrict the domain or extend the codomain of a translator by just using it as a function I => Option[O]. However this should be done after making all OrElse combinations, as the wrapped translator does not combine recursively.

A typical example of usage is as below

scala> import provingground._
import provingground._

scala> import translation._, Translator._
import translation._
import Translator._

scala> import cats._, cats.implicits._
import cats._
import cats.implicits._

scala> class A
defined class A

scala> case class B(x: A, y: A) extends A
defined class B

scala> case class C(x: A, y: A) extends A
defined class C

scala> case object D extends A
defined object D

scala> import Functors._
import Functors._

scala> val Bpat = Pattern.partial[A, II]{case B(x, y) => (x, y)}


scala> val Dpat = Pattern.partial[A, Un]{case D => ()}


scala> case object E extends A
defined object E

scala> val trans = Translator.Empty[A, A] || Bpat >>> {case (x, y) => C(x,y)} || Dpat >>> {case _ => E}
trans: provingground.translation.Translator.OrElse[A,A] = <function1>

scala> trans(B(B(D, D), B(B(D, D), D)))
res0: Option[A] = Some(C(C(E,E),C(C(E,E),E)))

scala> trans(C(D, D))
res1: Option[A] = None
Self Type
Translator[I, O]
Linear Supertypes
(I) => Option[O], AnyRef, Any
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Translator
  2. Function1
  3. AnyRef
  4. Any
Implicitly
  1. by UnliftOps
  2. by any2stringadd
  3. by StringFormat
  4. by Ensuring
  5. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def recTranslate(leafMap: => (I) => Option[O]): (I) => Option[O]

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toany2stringadd[Translator[I, O]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Translator[I, O], B)
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toArrowAssoc[Translator[I, O]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. def andThen[A](g: (Option[O]) => A): (I) => A
    Definition Classes
    Function1
    Annotations
    @unspecialized()
  7. def apply(inp: I): Option[O]
    Definition Classes
    Translator → Function1
  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  10. def compose[A](g: (A) => I): (A) => Option[O]
    Definition Classes
    Function1
    Annotations
    @unspecialized()
  11. def elseOr(that: Translator[I, O]): OrElse[I, O]

    OrElse combinator, tries other translator first, then this one.

    OrElse combinator, tries other translator first, then this one. Other translator must be preprended

  12. def ensuring(cond: (Translator[I, O]) => Boolean, msg: => Any): Translator[I, O]
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toEnsuring[Translator[I, O]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: (Translator[I, O]) => Boolean): Translator[I, O]
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toEnsuring[Translator[I, O]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean, msg: => Any): Translator[I, O]
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toEnsuring[Translator[I, O]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: Boolean): Translator[I, O]
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toEnsuring[Translator[I, O]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  18. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toStringFormat[Translator[I, O]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  19. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  20. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  21. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  22. def map[X](fn: (O) => X, ufn: (X) => O): Mapped[I, O, X]
  23. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  24. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  25. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  26. def orElse(that: Translator[I, O]): OrElse[I, O]

    OrElse combinator, tries other translator if the first fails.

  27. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  28. def toString(): String
    Definition Classes
    Function1 → AnyRef → Any
  29. def unlift: PartialFunction[I, O]
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toUnliftOps[I, O] performed by method UnliftOps in scala.Function1.
    Definition Classes
    UnliftOps
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  32. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  33. def ||(that: Translator[I, O]): OrElse[I, O]

    OrElse combinator, tries other translator if the first fails.

  34. def ||:(that: Translator[I, O]): OrElse[I, O]

    OrElse combinator, tries other translator first, then this one.

    OrElse combinator, tries other translator first, then this one. Other translator must be preprended

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated
  2. def [B](y: B): (Translator[I, O], B)
    Implicit
    This member is added by an implicit conversion from Translator[I, O] toArrowAssoc[Translator[I, O]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use -> instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

Inherited from (I) => Option[O]

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion UnliftOps fromTranslator[I, O] to UnliftOps[I, O]

Inherited by implicit conversion any2stringadd fromTranslator[I, O] to any2stringadd[Translator[I, O]]

Inherited by implicit conversion StringFormat fromTranslator[I, O] to StringFormat[Translator[I, O]]

Inherited by implicit conversion Ensuring fromTranslator[I, O] to Ensuring[Translator[I, O]]

Inherited by implicit conversion ArrowAssoc fromTranslator[I, O] to ArrowAssoc[Translator[I, O]]

Ungrouped