You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.5 KiB

package green.thisfieldwas.embracingnondeterminism
/** This package contains classes that represent contexts encoding some
* measurable dimension whose quantities at runtime are unknown due to some
* nondeterministic effects. These effects impact how instances of the term
* contained within the contexts are produced.
* See each class for specific examples.
package object data {
/** The identity context. This context has the identity of the value
* contained, and is thus the value contained. This context is always in the
* desired case as its instance is always present.
* @tparam A
* The type of the value.
type Id[A] = A
object Id {
implicit val idFunctor: Functor[Id] = new Functor[Id] {
/** Given a structure `F[A]` and function `f: A => B`, if the structure is
* in the desired case, then apply the function such that `F[A] => F[B]`.
* If the structure `F[A]` is in the undesired case, then propagate the
* undesired case as `F[B]`.
* @param fa
* The instance of the structure to apply the function to.
* @param f
* The function to apply, if the structure is in the desired case.
* @tparam A
* The type of instances contained within the structure.
* @tparam B
* The type to map the instances into.
* @return
* The resulting structure.
override def map[A, B](fa: Id[A])(f: A => B): Id[B] = f(fa)