Permalink
Browse files

Refs #2456 : add a new sequence control to skip Empty entry, and stil…

…l fail on Failure
  • Loading branch information...
1 parent 179325e commit 80a3cdf0032810ec915179bd90c5c894bb326709 @ncharles ncharles committed Apr 20, 2012
Showing with 12 additions and 1 deletion.
  1. +12 −1 utils/src/main/scala/com/normation/utils/Control.scala
@@ -51,6 +51,17 @@ object Control {
} }
Full(buf)
}
+
+ def sequenceEmptyable[U,T](seq:Seq[U])(f:U => Box[T]) : Box[Seq[T]] = {
+ val buf = scala.collection.mutable.Buffer[T]()
+ seq.foreach { u => f(u) match {
+ case f:Failure => return f
+ case Empty => // nothing to do
+ case Full(x) => buf += x
+ } }
+ Full(buf)
+ }
+
/**
* A version of sequence that will try to reach the end and accumulate
@@ -94,4 +105,4 @@ object Control {
}
}
}
-}
+}

0 comments on commit 80a3cdf

Please sign in to comment.