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]
- Alphabetic
- By Inheritance
- Translator
- Function1
- AnyRef
- Any
- by UnliftOps
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def recTranslate(leafMap: => (I) => Option[O]): (I) => Option[O]
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- 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
- 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()
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def andThen[A](g: (Option[O]) => A): (I) => A
- Definition Classes
- Function1
- Annotations
- @unspecialized()
- def apply(inp: I): Option[O]
- Definition Classes
- Translator → Function1
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def compose[A](g: (A) => I): (A) => Option[O]
- Definition Classes
- Function1
- Annotations
- @unspecialized()
- 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
- 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
- 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
- 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
- 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
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- 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()
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[X](fn: (O) => X, ufn: (X) => O): Mapped[I, O, X]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def orElse(that: Translator[I, O]): OrElse[I, O]
OrElse combinator, tries other translator if the first fails.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- Function1 → AnyRef → Any
- 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
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def ||(that: Translator[I, O]): OrElse[I, O]
OrElse combinator, tries other translator if the first fails.
- 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
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
- 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.