Pattern match on value of Either inside a for comprehension?

前端 未结 4 1804
無奈伤痛
無奈伤痛 2021-01-18 04:58

I have a for comprehension like this:

for {
      (value1: String, value2: String, value3: String) <- getConfigs(args)
      // more stuff using those val         


        
4条回答
  •  无人共我
    2021-01-18 05:55

    I think the part you may find surprising is that the Scala compiler emits this error because you deconstruct the tuple in place. This is surprisingly forces the compiler to check for withFilter method because it looks to the compilers like an implicit check for the type of the value inside the container and checks on values are implemented using withFilter. If you write your code as

      for {
        tmp <- getConfigs(args)
        (value1: Seq[String], value2: String, value3: String) = tmp
        // more stuff using those values
      } 
    

    it should compile without errors.

提交回复
热议问题