progs/lecture5.scala
changeset 507 2e3945ff7b66
parent 491 2a30c7dfe3ed
--- a/progs/lecture5.scala	Fri Dec 05 10:20:00 2025 +0000
+++ b/progs/lecture5.scala	Thu Dec 11 13:23:30 2025 +0000
@@ -1,12 +1,36 @@
 // Scala Lecture 5
 //=================
 
-def foo(n: Int) = ???
+// (Immutable) OOP
+
+
+import scala.util._      // Try,...
+import io.Source         // fromURL
+
+val my_url = "https://urbanchr.github.io/"
+
+
+
+
+Source.fromURL(my_url)(using "ISO-8859-1").mkString
+
+Try(Source.fromURL(my_url)(using "ISO-8859-1").mkString).toOption
 
-fop(10)
+Try(Source.fromURL(my_url)(using "ISO-8859-1").mkString).getOrElse("")
+
+
+// the same for files
+
+Try(Some(Source.fromFile("test.txt")(using "ISO-8859-1").mkString)).getOrElse(None)
 
-List.fill(1)(100)
-// (Immutable) OOP
+// how to implement a function for reading 
+// (lines) from files...
+//
+def get_contents(name: String) : List[String] = 
+  Try(Source.fromURL(name)(using "ISO-8859-1").getLines().toList).getOrElse(Nil)
+
+get_contents(my_url)
+
 
 // Object Oriented Programming in Scala
 // =====================================