ReversibleFunction

trait ReversibleFunction[A, B] extends A => B

Bi-Directional Function

ReversibleFunction allows to convert value to some type and back

It is used in two way binded collections

  val intToChar: ReversibleFunction[Int,Char] = ReversibleFunction(i => ('A' + i).toChar, _ - 'A')

  val list:  Idx.M[Int] = ~~(0, 2, 4).toBuffer
  val view:  Idx.M[Char] = list.mutableMap_^(intToChar)

  list.~.tp     // Prints ~(0, 2, 4)
  view.~.tp     // Prints ~(A, C, E)

  view(1) = 'Z' // Note, only second collection is updated, but both are changed

  list.~.tp     // Prints ~(0, 25, 4)
  view.~.tp     // Prints ~(A, Z, E)
Source
ReversibleFunction.scala
trait A => B
class java.lang.Object
trait scala.Matchable
class Any

Def

def apply(v: A): B
override def toString(): String
Definition Classes
Function1 -> Any
Inherited from
Function1
def undo(v: B): A

Undo map

Undo map

Restores conversion result to original value

Source
ReversibleFunction.scala

Extension

def reverse[A, B]: ReversibleFunction[B, A]

Reverses two functions

Reverses two functions

apply becomes undo and undo becomes apply

Source
ReversibleFunction.scala