For comprehensions don't do a good job with type inference when exploding tuples. Instead they pattern match. See https://stackoverflow.com/questions/30401942/why-does-a-for-comprehension-expand-to-a-withfilter/45768795#45768795
          Created
          August 19, 2017 07:14 
        
      - 
      
 - 
        
Save mattroberts297/89cc9b6449f601c3ce0139f0c06da569 to your computer and use it in GitHub Desktop.  
    Scala for comprehensions and withFilter
  
        
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | libraryDependencies += "org.typelevel" %% "cats-core" % "1.0.0-MF" | |
| scalaVersion := "2.12.2" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cats._ | |
| import cats.data._ | |
| import cats.implicits._ | |
| object CatsNEL extends App { | |
| val nss: NonEmptyList[(Int, String)] = NonEmptyList.of((1,"a"), (2, "b"), (3, "c")) | |
| val ss: NonEmptyList[String] = for { | |
| tuple <- nss | |
| (n, s) = tuple | |
| } yield s | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cats._ | |
| import cats.data._ | |
| import cats.implicits._ | |
| object CatsNEL extends App { | |
| val nss: NonEmptyList[(Int, String)] = NonEmptyList.of((1,"a"), (2, "b"), (3, "c")) | |
| val ss: NonEmptyList[String] = for { | |
| (n, s) <- nss | |
| } yield s | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment