--- 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 */