more operations;
authorwenzelm
Sun, 05 Mar 2023 15:19:17 +0100
changeset 77515 6aae7486e94a
parent 77514 acaa89cb977b
child 77516 71e3e144dc08
more operations;
src/Pure/ROOT.scala
src/Pure/library.scala
--- a/src/Pure/ROOT.scala	Sun Mar 05 14:53:32 2023 +0100
+++ b/src/Pure/ROOT.scala	Sun Mar 05 15:19:17 2023 +0100
@@ -9,7 +9,11 @@
   val error = Exn.error _
   def cat_error(msgs: String*): Nothing = Exn.cat_error(msgs:_*)
 
-  def using[A <: AutoCloseable, B](a: A)(f: A => B): B = Library.using(a)(f)
+  def using[A <: AutoCloseable, B](a: A)(f: A => B): B =
+    Library.using(a)(f)
+  def using_option[A <: AutoCloseable, B](opt: Option[A])(f: A => B): Option[B] =
+    Library.using_option(opt)(f)
+
   val space_explode = Library.space_explode _
   val split_lines = Library.split_lines _
   val cat_lines = Library.cat_lines _
@@ -22,4 +26,3 @@
   def proper_list[A](list: List[A]): Option[List[A]] = Library.proper_list(list)
   def if_proper[A](x: Iterable[A], body: => String): String = Library.if_proper(x, body)
 }
-
--- a/src/Pure/library.scala	Sun Mar 05 14:53:32 2023 +0100
+++ b/src/Pure/library.scala	Sun Mar 05 15:19:17 2023 +0100
@@ -20,6 +20,9 @@
     finally { if (a != null) a.close() }
   }
 
+  def using_option[A <: AutoCloseable, B](opt: Option[A])(f: A => B): Option[B] =
+    opt.map(a => using(a)(f))
+
 
   /* integers */