问题标签 [scala-cats]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
scala - 如何使用 Scalaz 或 Cats 重构抛出异常的函数
这是我之前的问题的后续行动:
假设我正在重构这样的函数:
我正在编写一个新的纯函数doCheck
来返回一个Unit
或一个异常。
然后从check
是否有意义 ?那样实施会更好doCheck
吗?
如何实现它cats
?
scala - scala:按类型联合参数化
我需要一个类型 Union 来强制限制类型,所以按照这里的答案,我将我的 Union 定义为:
现在,我如何创建由这种类型联合参数化的列表或类?有可能这样做吗?我在 repl 中尝试了以下语法,但没有任何运气:
或者是否可以使用scalaz或cats等高级FP库来做到这一点?
scala - Lift values on Applicative
This question is based on the scala cats library, but I guess could apply to scalaz
or general functional programming.
I'm trying the cats exercises and I thought of the following functionality with Applicative
: Is there a function with the following signature and if so, what's it's name?
That is, if I have a function lying around that takes two Applicative
instances and produces a third as result (f
), I want to apply it to 2 values x
and y
without having to wrap it in an Applicative
myself with pure
. I can easily implement it myself like:
but it looked like something that might exist already and I couldn't find anything. (pureMap
sounded like a reasonable name).
An example would be, if I already had a function in a validation library like:
, then I would want to use it like:
scala - 在猫 XorT 中组合不同的“容器”
例如,我们有一些带有不同“容器”的服务,Future
并且Option
:
我们如何将它们结合起来使用一个来进行理解以避免类型不匹配?
scala - Kleisli 示例需要显式类型和 FlatMap[Option]?
我正在玩基本的Kleisli 示例
有两件事让我着迷
- 为什么我需要明确指定类型 [Option,String,Int]?示例代码省略了它们,我猜它一定也以这种方式工作......
- 评估
c
像c("5")
我真的需要FlatMap[Option]
手动给出还是我缺少一个隐式导入?
我可以加
评估c("5")
,但是这东西没有默认实现吗?
scala - Using abstract types with type classes in Scala
I want to use an abstract type Value
constrained to belong to the type class Show
from cats.
My first attempt would be something like:
But the compiler doesn't find the implicit parameter Show[Value]
.
I know that I can define the previous example as:
However, I wanted to know if it is possible to use abstract types instead of type parameters.
intellij-idea - 带有种类投影仪插件的 IntelliJ 上的猫
我正在探索 IntelliJ 中的 Cats,但尽管 IntelliJ Scala 插件支持Kind Projector 插件,但 IntelliJ 无法识别插件的类型 lambda 表示法 ( λ
)。启用此功能有诀窍吗?在运行代码检查后,我没有看到 Kind Projector 列出,尽管 Kind Projector 检查选项可用并在首选项中启用。我的 IntelliJ 版本是 2016.2.2,Scala 插件版本是 2016.2.1。
scala - 猫的约定:在哪里声明类型类实例
假设你有一些类A
,并且你想T
为A
. 实例声明应该放在哪里?就我个人而言,我会将它放在 class 的伴随对象中A
。例如,如果我要为 Monoid 声明一个实例,我会这样写:
但是我找不到关于这个问题的任何约定。有没有更好或推荐的方法?