Representable.
Representable.
Is a witness to the isomorphism forall A. F[A] <-> Representation => A
Must obey the laws defined in cats.laws.RepresentableLaws i.e. tabulate andThen index = identity index andThen tabulate = identity
Inspired by the Haskell representable package http://hackage.haskell.org/package/representable-functors-3.2.0.2/docs/Data-Functor-Representable.html
- Companion
- object
trait Serializable
class Object
trait Matchable
class Any
Type members
Types
Value members
Abstract methods
Create a function that "indexes" into the F
structure using Representation
Create a function that "indexes" into the F
structure using Representation
Example:
scala> import cats.implicits._
scala> type Pair[A] = (A, A)
scala> val indexed: Boolean => String = Representable[Pair].index(("foo", "bar"))
scala> indexed(true)
res0: String = foo
scala> indexed(false)
res1: String = bar
Reconstructs the F
structure using the index function
Reconstructs the F
structure using the index function
Example:
scala> import cats.implicits._
scala> type Pair[A] = (A, A)
scala> val f: Boolean => String = {
| case true => "foo"
| case false => "bar"
| }
scala> f.tabulate[Pair]
res0: Pair[String] = (foo,bar)