scrutinee is incompatible with pattern type; found : Option[String] required: String

940 views
Skip to first unread message

miki haiat

unread,
Jan 7, 2015, 4:40:41 PM1/7/15
to scala...@googlegroups.com
I have issue with the return type from a for yield loop ,

i have this method and for some reason , i'm still new to scala...   im getting this error and a warning .

this is the method ,


def getPostMD(userID: String,url:String):Future[(Option[String],List[PostMD])]={
 
  val chunk
: Future[JsValue] = Methods.getJsonValue(url)


    chunk
.flatMap(ch => {
     val   postMd
: Option[List[PostMD]] = (ch \ "data").asOpt[List[PostMD]]
     
for{
         relatedPostMd
:List[PostMD] <- postMd.get.filter(_.fromID == userID)        
         nextUrl
: Option [String] <-(ch \ "paging" \ "next").asOpt[String]
       
}yield(nextUrl,relatedPostMd)    
     
}
}


the warning is ,

fruitless type test: a value of type PostMetaData.this.PostMD cannot also be a List[PostMetaData.this.PostMD] (the underlying of List[PostMetaData.this.PostMD])

and the error is ,

scrutinee is incompatible with pattern type; found : Option[String] required: String


What is wrong with my method  and what is  fruitless type ??

thanks,

miki

     
  

Som Snytt

unread,
Jan 7, 2015, 5:09:08 PM1/7/15
to miki haiat, scala-user
Probably just remove the type annotations from the for comprehension.

for (i <- List(1,2,3)) ...

instead of

for (i: Int <- List(1,2,3))...

This is wrong:
for (i: List[Int] <- List(1,2,3))...


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Som Snytt

unread,
Jan 7, 2015, 5:11:18 PM1/7/15
to miki haiat, scala-user
Reply all
Reply to author
Forward
0 new messages