我当时正在处理应用程序,遇到了想要对可追加集合进行抽象的情况。我想出了下面的类型类。
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
}
}它看起来有点像零的应用,但我打赌猫或它的生态系统中也有类似的东西?
发布于 2019-11-01 11:03:59
如果有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://stackoverflow.com/questions/58650248
复制相似问题