I'm really confused here, i'm probably missing something obvious so it would be great if someone could point me into the right direction.
I've got this following function that returns a future of a SimpleResult type but it has a unit instead . I'm not sure why it is saying this as i am mapping the futureList result
def find(key: String, value: String) = Future[SimpleResult] {
val cursor: Cursor[JsObject] = coll.
find(Json.obj(key -> value)).
cursor[JsObject]
val futureList: Future[List[JsObject]] = cursor.collect[List]()
val futureResult: Future[SimpleResult] = futureList.map { item =>
if(item.isEmpty) {
Ok(JsArray()).as(JSON)
}
else
Ok(Json.toJson(item))
}
}
Edit
I've changed it to the following from the advice given by Marth
def find(key: String, value: String) = Future[SimpleResult] {
val cursor: Cursor[JsObject] = coll.
find(Json.obj(key -> value)).
cursor[JsObject]
val futureList: Future[List[JsObject]] = cursor.collect[List]()
futureList.map { item => Ok(Json.toJson(item)) }
}
Eclipse is warning about the following
type mismatch; found : scala.concurrent.Future[play.api.mvc.SimpleResult] required: play.api.mvc.SimpleResult
Although the function is meant to return a scala.concurrent.Future[play.api.mvc.SimpleResult]