markusthoemmes commented on a change in pull request #3950: Extend system 
testsuite
URL: 
https://github.com/apache/incubator-openwhisk/pull/3950#discussion_r209897675
 
 

 ##########
 File path: tests/src/test/scala/common/rest/WskRestOperations.scala
 ##########
 @@ -733,13 +738,23 @@ class RestActivationOperations(implicit val actorSystem: 
ActorSystem)
                    fieldFilter: Option[String] = None,
                    last: Option[Boolean] = None,
                    summary: Option[Boolean] = None)(implicit wp: WskProps): 
RestResult = {
-    val rr = activationId match {
+    val actId = activationId match {
+      case Some(id) => activationId
+      case None =>
+        last match {
+          case Some(true) => {
+            val activations = pollFor(N = 1, entity = None, limit = Some(1))
+            require(activations.size <= 1)
+            if (activations.isEmpty) None else Some(activations.head)
+          }
+          case _ => None
 
 Review comment:
   Right, this can be rewritten to:
   
   ```scala
   val actId = activationId.orElse(last.filter(_ == true).flatMap { _ =>
     val activations = pollFor(N = 1, entity = None, limit = Some(1))
     require(activations.size <= 1)
     activations.headOption
   })
   ```
   
   `orElse` returns the value of the first option (activationId in your case) 
or falls back to a second option.
   `filter` on an option returns a None if the filter is not fullfilled.
   `headOption` returns the head of a list, if its non-empty, otherwise None.
   
   Optional to implement, just mentioning how combinators could be used here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to