- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这适用于 scalaz 7.0.6,但不适用于最新版本的 scalaz 7.2.6。
import scalaz._, Scalaz._
def allDigits(s: String): Validation[String, String] =
if (s.forall(_.isDigit)) s.success else "Not all digits".failure
def maxSizeOfTen(s: String): Validation[String, String] =
if (s.length <= 10) s.success else "Too big".failure
def toInt(s: String) = try s.toInt.success catch {
case _: NumberFormatException => "Still not an integer".failure
}
val validated1 = for {
x <- allDigits("4234")
y <- maxSizeOfTen(x)
z <- toInt(y)
} yield z
value flatMap is not a member of scalaz.Validation[String,String]
x <- allDigits("4234")
value flatMap is not a member of scalaz.Validation[String,String]
y <- maxSizeOfTen(x)
...
import scalaz._, Scalaz._
def allDigits(s: String): \/[String, String] =
if (s.forall(_.isDigit)) s.right else "Not all digits".left
def maxSizeOfTen(s: String): \/[String, String] =
if (s.length <= 10) s.right else "Too big".left
def toInt(s: String) = try s.toInt.right catch {
case _: NumberFormatException => "Still not an integer".left
}
val validated1 = for {
x <- allDigits("4234")
y <- maxSizeOfTen(x)
z <- toInt(y)
} yield z
最佳答案
验证不应与 flatMap
一起使用,因为它旨在累积失败,因此具有 Applicative
独立(无上下文)计算的实例。 \/
应该在您的情况下使用(依赖(或上下文相关)计算)。
尽管如此,通过添加此导入,您可以实现您想要的:import Validation.FlatMap._
关于scalaz 7.2.6 flatMap 不是验证方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39465402/
我有一个对象Foo,其中包含Bar列表。这些类的描述如下: class Foo { String name; List bars = new ArrayList(); Foo(
根据 Mozilla 开发者网站: flatMap() 方法首先使用映射函数映射每个元素,然后将结果展平到一个新数组中。它与 map 后跟深度为 1 的 flat 相同,但 flatMap 通常非常有
我对无法找到该问题的现有问题感到非常惊讶。这是为什么,鉴于: val p: Int => Option[Int] = Some(_) List(1, 2, 3).flatMap(p) 我得到: :14
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 5 年前。 Improve th
我想知道两种平面映射情况之间是否存在显着差异。 案例 1: someCollection .stream() .map(CollectionElement::getAnotherCol
以下是flatMap的定义取自 scala.util.Success。 final case class Success[+T](value: T) extends Try[T] { def fl
我正在寻找一个函数来展平列表数组。首先,我在 RDD 系统上使用 Apach Spark 函数 flatMap 实现了我的解决方案,但我想在本地执行此操作。但是,我无法找到 的等价物 samples
我想知道是否存在忽略 flatMap 中的结果的函数(在 scala 或 cat 中) .例如。 Some("ignore this").ignoreArgumentFlatMap(Some("res
我正在学习 Scala 并解决了 99 个 Scala 问题。对于以下练习: 展平嵌套列表结构。示例: scala> flatten(List(List(1, 1), 2, List(3, List(
当编译器进入无限循环时,是否有人遇到过使用此类 flatMap 链(或什至更长)的问题。 let what = Future.init { (promise) in promise(.succ
有没有更好的函数方式来写 flatMap ? def flatMap[A,B](list: List[A])(f: A => List[B]): List[B] = list.map(x =>
我试图从两个 中变出笛卡尔积潜在无限然后我通过 limit() 限制的流. 到目前为止,这(大约)是我的策略: @Test void flatMapIsLazy() { Stream.
为什么以下声明对 .map() 有效但不适用于 .flatMap() ? val tupled = input.map(x => (x*2, x*3)) //Compilation error:
我正在寻找可以同时映射和展平 Lists 和 Maybes 的代码。我在 this topic 中发现了这样一个 flatMap 函数: flatMap :: (t -> [a]) -> [t] ->
考虑在某些大小写匹配上编写的 flatMap。例如: list.flatMap( v => v match { case Cond1 => if(something) Some
我无法使用ListKOf平面映射T -> Option。 例如 listOf(1,2,3).k().flatMap { i -> if (i % 2 == 0) Some(i) else None
有人可以解释我如何在RxJava中通过flatMap运算符传递onComplete信号吗? 如果对flatMap运算符进行注释,则可以获取1到10的数字列表,这意味着toList将收到onComple
我正在做一个在线类(class)并误读了一个问题(这就是为什么我认为可以发布这个问题,因为答案与类(class)中的问题无关!)。 data class Trip( val drive
给定作为数据类的二维坐标列表 data class Point(val x: Int, val y:Int) val points: List 和 TornadoFX(Kotlin 中的 JavaFX
这个问题已经有答案了: What is the difference between .stream() and Stream.of? (5 个回答) 已关闭 3 年前。 我有以下代码: List p
我是一名优秀的程序员,十分优秀!