加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – List [String]没有来自cats的成员遍历

发布时间:2020-12-16 18:21:22 所属栏目:安全 来源:网络整理
导读:我试图使用来自猫的遍历将List [Either [Int]]转换为[List [Int]]. 错误 [error] StringCalculator.scala:19:15: value traverseU is not a member of List[String][error] numList.traverseU(x = { 码 import cats.Semigroup import cats.syntax.traverse._
我试图使用来自猫的遍历将List [Either [Int]]转换为[List [Int]].

错误

[error] StringCalculator.scala:19:15: value traverseU is not a member of List[String]
[error]       numList.traverseU(x => {

import cats.Semigroup
  import cats.syntax.traverse._
  import cats.implicits._


  val numList = numbers.split(',').toList
  numList.traverseU(x => {
      try {
          Right(x.toInt)
      } catch {
        case e: NumberFormatException => Left(0)
      }
    })
      .fold(
        x => {},x => {}
      )

I have tried the same with traverse instead of traverseU as well.

配置(用于猫)

lazy val root = (project in file(".")).
  settings(
    inThisBuild(List(
      organization := "com.example",scalaVersion := "2.12.4",scalacOptions += "-Ypartial-unification",version      := "0.1.0-SNAPSHOT"
    )),name := "Hello",libraryDependencies += cats,libraryDependencies += scalaTest % Test
  )

解决方法

它应该只是遍历,只要您使用最近的猫版本(1.0.x),但是,您不能同时导入cats.syntax和cats.implicits._,因为它们会发生冲突.

不幸的是,每当Scala编译器发现implicits冲突时,它都会给你一个非常无益的消息.

删除cats.syntax导入,它应该工作正常.
有关详细信息,请查看import guide.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读