Please enable JavaScript.
Coggle requires JavaScript to display documents.
Scalaz (Lens (Lens =>= f (apply function on result of Lens.get, f(Lens…
Scalaz
Lens
-
-
-
Lens =>= f
apply function on result of Lens.get, f(Lens.get(x))
compose (<=<)
Lens[B,C] <=< Lens[A,B] = Lens[A,C]
andThen (>=>)
Lens[A,B] >=> Lens[B,C] = Lens[A,C]
-
lensu(setFunc:(S,T) => S, getFunc:S=>T):Lens[S,T]
State[S,A]
S => (S,A)
takes a state and return new state and a value
-
runZero(implicit S: Monoid[S]): F[(S,A)] = run(S.zero)
-
flatMap(f: A => State[S,A]) / bind / >>=
extract value A from the State[S,A] and apply to given function f
gets[S,T](f:S=>T):State[S,T] = State(s => (s, f(s)))
-
putS:State[S,Unit] = State(s => (s. f(s)))
object State.apply(f: S => (S,A))
return a new State[S,+A] instance with apply(s:S)
Monad
-
-
-
Monad transformer
-
OptionT[M[_], A] create a Option[A] inside M
monad transformer is built from inside out
-
-
Id
-
doWhile(f: A=>A, p: A=>Boolean):A
-
whileDo(f: A=>A, p:A=>Boolean):A
-
visit[F[_] : Pointed](p: PartialFunction[A,F[A]]): F[A]
if partial func is defined for self, run this func,
otherwise lift self into F with the Pointed in context bound
-
-
Applicative
-
-
extract value
^
^(3.some, 5.some) { _ + _ } returns Some(8)
doesn't handle Applicatives that take 2 type params, like Function1[In,Out]
-
lift2
scala> Apply[Option].lift2((_: Int) :: (_: List[Int]))
res66: (Option[Int], Option[List[Int]]) => Option[List[Int]] = <function2>
scala> res66(3.some, List(4).some)
res67: Option[List[Int]] = Some(List(3, 4))
-
Functor
-
def map[A, B](fa:F[A])(f: a=>B):F[B]
// lift f into F and apply to F[A]
-
Functor Laws
- map the id function over a functor will return the same functor as input
- composing 2 functions and then mapping the resulting function over a functor
=
first mapping one function over the functor and then mapping the second function
-
-
-
Monoid
-
-
Tags
-
-
-
Ordering
allows 2-level comparing, e.g. string compare
Laws
-
- left identity: forall a. append(zerp, a) == a
- right identity: forall a. append(a, zero) == a
-
-
TypeClass
-
To be a member of a TypeClass,
must provide the defined behaviors.
e.g. Ordering[A] is a TypeClass that defines
def compare(a1:A, a2:A):Int
if type Int want to be member of Ordering[A], it need to provide def compare(a1:Int, a2:Int):Int
Tagged type
-
type Tagged[U] = { type Tag = U }
type @[T, U] = T with Tagged[U]
ST[S,A]
Similar to State[S,A] but hide state S, not accessible
mutable State STRef[S,A] is mutated in-place
-
SemiGroup
Laws
- clousure: ∀ a, b in F, append(a, b) is also in F
- associativity: ∀ a, b, c in F, the equation append(append(a, b), c) = append(a, append(b , c)) holds