Ai
1 Star 0 Fork 0

mefan/cats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MonadCombine.scala 674 Bytes
一键复制 编辑 原始数据 按行查看 历史
Adelbert Chang 提交于 2015-07-01 12:56 +08:00 . Turn on -Ywarn-unused-import
package cats
import simulacrum.typeclass
/**
* The combination of a Monad with a MonoidK
*/
@typeclass trait MonadCombine[F[_]] extends MonadFilter[F] with Alternative[F] {
/**
* fold over the inner structure to combining all the values with
* our combine method inherited from MonoidK. The result is for us
* to accumulate all of the "interesting" values of the innner G, so
* if G is Option, we collect all the Some values, if G is Xor,
* we collect all the Right values, etc.
*/
def unite[G[_], A](fga: F[G[A]])(implicit G: Foldable[G]): F[A] =
flatMap(fga) { ga =>
G.foldLeft(ga, empty[A])((acc, a) => combine(acc, pure(a)))
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mefaso/cats.git
git@gitee.com:mefaso/cats.git
mefaso
cats
cats
master

搜索帮助