progs/lecture2.scala
changeset 36 f5ed0fef41b3
parent 13 0ce25f816414
child 37 38f3868891f0
--- a/progs/lecture2.scala	Thu Nov 10 11:41:50 2016 +0000
+++ b/progs/lecture2.scala	Thu Nov 10 16:10:39 2016 +0000
@@ -1,2 +1,23 @@
 // sudoku
 // some none
+
+
+
+
+// Implicits
+//===========
+//
+// for example adding your own methods to Strings:
+// imagine you want to increment strings, like
+//
+//     "HAL".increment
+//
+// you can avoid ugly fudges, like a MyString, by
+// using implicit conversions
+
+
+implicit class MyString(s: String) {
+  def increment = for (c <- s) yield (c + 1).toChar 
+}
+
+"HAL".increment