简体   繁体   English

适用于零

[英]Applicative with zero

I was just working on application and encountered case where I'd like to abstract over appendable collections.我只是在处理应用程序并遇到了我想对可附加的 collections 进行抽象的情况。 I came up with the following type class.我想出了以下类型 class。

trait AppendableCollection[F[_]] {
  def empty[A]: F[A]
  def append[A](fa: F[A])(a: A): F[A]
}

object AppendableCollection {
  implicit val reversedListCollection = new Collection[List] {
    def empty[A] = Nil
    def append[A](fa: List[A])(a: A) = a :: fa
  }
}

It kinda looks like Applicative with zero but and I bet there is something like this available in cats or its ecosystem?它有点像零的应用程序,但我敢打赌猫或其生态系统中有类似的东西?

Provided there is pure(a: A): F[A] , looks similar to MonoidK假设有pure(a: A): F[A] ,看起来类似于MonoidK

trait MonoidK[F[_]] {
  def empty[A]: F[A]
  def combineK[A](x: F[A], y: F[A]): F[A]
}

https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/MonoidK.scala#L25 https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/MonoidK.scala#L25

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM