Scala Cats

Semigroup

A semigroup is any set A with an associative operation (combine). --Scala Cats

trait Semigroup[A] {
  def combine(x: A, y: A): A
}

Monoid

A monoid is a semigroup with an identity. A monoid is a specialization of a semigroup, so its operation must be associative. Additionally, combine(x, empty) == combine(empty, x) == x. For example, if we have Monoid[String], with combine as string concatenation, then empty = "". --Scala Cats

trait Monoid[A] extends Semigroup[A] {
  def empty: A
}

Functors

Functor.
The name is shorts for "covariant functor".
Must obey the laws defined in cats.laws.FunctorLaws.--Scala Cats

trait Functor[F[_]] {
  def map[A, B](fa: F[A])(f: A => B): F[B]
}

Monads

Monad.
Allows composition of dependent effectful functions.
See: Monads for functional programming
Must obey the laws defined in cats.laws.MonadLaws.

trait Monad[F[_]] extends Functor[F] {
  def pure[A](value: A): F[A]
  def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B]
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • http://spark.apache.org/docs/latest/api/python/index.html...
    mpro阅读 11,287评论 0 4
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,129评论 0 10
  • Spark算子总结 算子分类 Transformation(转换)转换算子含义map(func)返回一个新的RDD...
    ronnie_yuan阅读 3,446评论 0 0
  • http://homepage.cs.latrobe.edu.au/zhe/ZhenHeSparkRDDAPIEx...
    scandly阅读 3,142评论 0 1
  • 背景 所有一切的开始都是因为这句话:一个单子(Monad)说白了不过就是自函子范畴上的一个幺半群而已,有什么难以理...
    福克斯记阅读 14,721评论 6 65