From d772fc3ba277b68a06c8eb072915e17512a29cf7 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Mon, 14 Oct 2013 01:18:31 +0900 Subject: [PATCH] refactoring. avoid Option#get --- src/main/scala/service/PullRequestService.scala | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/scala/service/PullRequestService.scala b/src/main/scala/service/PullRequestService.scala index 950c4d3f6..5374b9996 100644 --- a/src/main/scala/service/PullRequestService.scala +++ b/src/main/scala/service/PullRequestService.scala @@ -9,13 +9,10 @@ trait PullRequestService { self: IssuesService => import PullRequestService._ def getPullRequest(owner: String, repository: String, issueId: Int): Option[(Issue, PullRequest)] = - defining(getIssue(owner, repository, issueId.toString)){ issue => - if(issue.isDefined){ - Query(PullRequests).filter(_.byPrimaryKey(owner, repository, issueId)).firstOption match { - case Some(pullreq) => Some((issue.get, pullreq)) - case None => None - } - } else None + getIssue(owner, repository, issueId.toString).flatMap{ issue => + Query(PullRequests).filter(_.byPrimaryKey(owner, repository, issueId)).firstOption.map{ + pullreq => (issue, pullreq) + } } def getPullRequestCountGroupByUser(closed: Boolean, owner: String, repository: Option[String]): List[PullRequestCount] = @@ -54,4 +51,4 @@ object PullRequestService { case class PullRequestCount(userName: String, count: Int) -} \ No newline at end of file +}