SlideShare a Scribd company logo
1 of 33
Download to read offline
1/33




                                                                    TÜRKİYE

                                 String Interpolation               presenter
                                                                    Volkan Yazıcı
                                            Streams                 https://twitter.com/yazicivo
                                Regular Expressions                 http://vyazici.blogspot.com
                                                                    http://github.com/vy
                                 Process Execution                  http://web.itu.edu.tr/~yazicivo/




https://groups.google.com/forum/?fromgroups=#!forum/scala-turkiye                                      2013-02-07
2/33




   Implicit Classes                                             simplify the creation of classes which
   provide extension methods to another type.




http://docs.scala-lang.org/sips/pending/implicit-classes.html
3/33



                        Implicit Classes
                                      Basics
scala> implicit class MyString(val str: String) {
     |   def quote: String = "'" + str + "'"
     | }
defined class MyString

scala> println("abc")
abc

scala> println("abc".quote)
'abc'
4/33



                        Implicit Classes
                                      Basics
scala> implicit class MyString(val str: String) {
     |   def quote: String = "'" + str + "'"
     | }
defined class MyString

scala> println("abc")
abc

scala> println("abc".quote)
'abc'

---------------------------------------------------------------------------------------

scala> implicit class MyInt(val n: Int) {
     |   def factorial: Int = {
     |     require(n >= 0)
     |     if (n < 2) 1
     |     else n * (n-1).factorial
     |   }
     | }
defined class MyInt

scala> 5.factorial
res3: Int = 120
5/33




   String Interpolation                                   allows users to embed
   variable references directly in processed string literals.




http://www.scala-lang.org/node/258
6/33



                 String Interpolation
                                      Basics
scala> val (str, num) = ("Walter White", 0.128F)
str: String = Walter White
num: Float = 0.128
7/33



                 String Interpolation
                                      Basics
scala> val (str, num) = ("Walter White", 0.128F)
str: String = Walter White
num: Float = 0.128

---------------------------------------------------------------------------------------

scala> println(s"str: $str, num: $num")
str: Walter White, num: 0.128
8/33



                 String Interpolation
                                      Basics
scala> val (str, num) = ("Walter White", 0.128F)
str: String = Walter White
num: Float = 0.128

---------------------------------------------------------------------------------------

scala> println(s"str: $str, num: $num")
str: Walter White, num: 0.128

---------------------------------------------------------------------------------------

scala> println(s"1 + 1 = ${1 + 1}”)
1 + 1 = 2

scala> println(s"2 * $num = ${2 * num}”)
2 * 0.128 = 0.256
9/33



                 String Interpolation
                                      Basics
scala> val (str, num) = ("Walter White", 0.128F)
str: String = Walter White
num: Float = 0.128

---------------------------------------------------------------------------------------

scala> println(s"str: $str, num: $num")
str: Walter White, num: 0.128

---------------------------------------------------------------------------------------

scala> println(s"1 + 1 = ${1 + 1}”)
1 + 1 = 2

scala> println(s"2 * $num = ${2 * num}”)
2 * 0.128 = 0.256

---------------------------------------------------------------------------------------

scala> println(f"num: $num%.2f")
Num: 0.13
10/33



                 String Interpolation
                                      Basics
scala> val (str, num) = ("Walter White", 0.128F)
str: String = Walter White
num: Float = 0.128

---------------------------------------------------------------------------------------

scala> println(s"str: $str, num: $num")
str: Walter White, num: 0.128

---------------------------------------------------------------------------------------

scala> println(s"1 + 1 = ${1 + 1}”)
1 + 1 = 2

scala> println(s"2 * $num = ${2 * num}”)
2 * 0.128 = 0.256

---------------------------------------------------------------------------------------

scala> println(f"num: $num%.2f")
Num: 0.13

---------------------------------------------------------------------------------------

scala> println(raw"anb u0040")
anb @
11/33



         String Interpolation
                     Internals



             Compiler transformation:

  id”string” ↔ StringContext(“string”).id()


  Existing StringContext methods: s, f, and raw.

We can extend StringContext using implicit classes.
12/33



                 String Interpolation
                                    Extending
scala> implicit class MyStringContext(val sc: StringContext) {
     |   def q(args: Any*): String = s"args: '$args', parts: '$sc.parts'"
     | }
defined class MyStringContext

scala> println(q"abc ${1+1} def")
args: 'WrappedArray(2)', parts: 'StringContext(WrappedArray(abc ,   def)).parts'
13/33




   A   Stream                       is like a list except that its elements are computed lazily.




http://www.scala-lang.org/api/current/scala/collection/immutable/Stream.html
14/33



                                Streams
                                        Basics
scala> Stream.cons(1, Stream.empty)
res0: Stream.Cons[Int] = Stream(1, ?)

scala> Stream.cons(1, Stream.empty): Stream[Int]
res1: Stream[Int] = Stream(1, ?)

scala> Stream.cons(1, Stream.empty).toList
res2: List[Int] = List(1)

scala> Stream.cons(1, Stream.cons(2, Stream.empty)).toList
res3: List[Int] = List(1, 2)
15/33



                                   Streams
                                        Basics
scala> Stream.cons(1, Stream.empty)
res0: Stream.Cons[Int] = Stream(1, ?)

scala> Stream.cons(1, Stream.empty): Stream[Int]
res1: Stream[Int] = Stream(1, ?)

scala> Stream.cons(1, Stream.empty).toList
res2: List[Int] = List(1)

scala> Stream.cons(1, Stream.cons(2, Stream.empty)).toList
res3: List[Int] = List(1, 2)

---------------------------------------------------------------------------------------

scala> def integers(n: Int): Stream[Int] = Stream.cons(n, integers(n+1))
integers: (from: Int)Stream[Int]

scala> integers(0)
res4: Stream[Int] = Stream(0, ?)

scala> integers(0).take(10)
res5: Stream[Int] = Stream(0, ?)

scala> integers(0).take(10).toList
res6: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
16/33



                                Streams
                                      Usage
scala> def evenNumbers: Stream[Int] = integers(0).filter(_ % 2 == 0)
evenNumbers: ()Stream[Int]

scala> evenNumbers.take(10).toList
res7: List[Int] = List(0, 2, 4, 6, 8, 10, 12, 14, 16, 18)
17/33



                                Streams
                                      Usage
scala> def evenNumbers: Stream[Int] = integers(0).filter(_ % 2 == 0)
evenNumbers: ()Stream[Int]

scala> evenNumbers.take(10).toList
res7: List[Int] = List(0, 2, 4, 6, 8, 10, 12, 14, 16, 18)

---------------------------------------------------------------------------------------

scala> Stream.continually(math.random).take(3).toList
res8: List[Double] = List(0.5932830094101399, 0.4377639789538802, 0.4522513999390704)
18/33



                                Streams
                                      Usage
scala> def evenNumbers: Stream[Int] = integers(0).filter(_ % 2 == 0)
evenNumbers: ()Stream[Int]

scala> evenNumbers.take(10).toList
res7: List[Int] = List(0, 2, 4, 6, 8, 10, 12, 14, 16, 18)

---------------------------------------------------------------------------------------

scala> Stream.continually(math.random).take(3).toList
res8: List[Double] = List(0.5932830094101399, 0.4377639789538802, 0.4522513999390704)

---------------------------------------------------------------------------------------

scala> Stream.continually(List(1,2,3)).flatten.take(8).toList
res9: List[Int] = List(1, 2, 3, 1, 2, 3, 1, 2)
19/33



                                Streams
                                Recursion [1/2]
scala> def fibonacci: Stream[Int] =
           1 #:: 1 #:: fibonacci.zip(fibonacci.tail).map { case (x, y) => x + y }
fibonacci: Stream[Int]

scala> fibonacci.take(10).toList
res8: List[Int] = List(1, 1, 2, 3, 5, 8, 13, 21, 34, 55)
20/33



                                Streams
                                Recursion [2/2]
scala> def primes(implicit n: Int = 2): Stream[Int] = integers(n) match {
         case x #:: xs => x #:: primes(x+1).filter(_ % x != 0)
       }
primes: (implicit n: Int)Stream[Int]

scala> primes.take(10).toList
res17: List[Int] = List(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
21/33



                                Streams
                                     Gotchas
scala> def naturalNumbers: Stream[Int] = integers(0)
naturalNumbers: ()Stream[Int]

scala> val naturalNumbers: Stream[Int] = integers(0)
naturalNumbers: Stream[Int] = Stream(0, ?)

scala> lazy val naturalNumbers: Stream[Int] = integers(0)
naturalNumbers: Stream[Int] = <lazy>
22/33




   Regular Expressions




http://www.scala-lang.org/api/current/index.html#scala.util.matching.Regex
23/33



                Regular Expressions
                                      Basics
scala> "0xDeadBeef" matches "0x[0-9a-fA-F]+"
res1: Boolean = true

scala> "abc 0x12 def" matches "0x[0-9a-fA-F]+"
res2: Boolean = false
24/33



                Regular Expressions
                                      Basics
scala> "0xDeadBeef" matches "0x[0-9a-fA-F]+"
res1: Boolean = true

scala> "abc 0x12 def" matches "0x[0-9a-fA-F]+"
res2: Boolean = false

---------------------------------------------------------------------------------------

scala> val dateRegex = "([0-9]{4})-([0-9]{2})-([0-9]{2})".r
hexregex: scala.util.matching.Regex = ([0-9]{4})-([0-9]{2})-([0-9]{2})

scala> dateRegex findFirstIn "2013-04-08" match {
     |   case Some(dateRegex(y, m, n)) => s"y: $y, m: $m, n: $n"
     |   case None => "invalid date"
     | }
res3: String = y: 2013, m: 04, n: 08

scala> dateRegex findAllIn "2013-04-08 2012-05-07" map {
     |   case dateRegex(y, m, n) => (y, m, n)
     | } toList
res4: List[(String, String, String)] = List((2013,04,08), (2012,05,07))
25/33




   Process Execution




http://www.scala-lang.org/api/current/index.html#scala.sys.process.package
26/33



                   Process Execution
                                    Basics
scala> import scala.sys.process._
import scala.sys.process._
27/33



                   Process Execution
                                      Basics
scala> import scala.sys.process._
import scala.sys.process._

---------------------------------------------------------------------------------------

scala> "/bin/false".!
res1: Int = 1

scala> "/bin/true".!
res2: Int = 0
28/33



                   Process Execution
                                           Basics
scala> import scala.sys.process._
import scala.sys.process._

---------------------------------------------------------------------------------------

scala> "/bin/false".!
res1: Int = 1

scala> "/bin/true".!
res2: Int = 0

---------------------------------------------------------------------------------------

scala> "uptime".!!
res3: String =
" 17:30:38 up 4 days,   3:41,   5 users,   load average: 1.18, 0.97, 0.79
"
29/33



                   Process Execution
                                      Basics
scala> import scala.sys.process._
import scala.sys.process._

---------------------------------------------------------------------------------------

scala> "/bin/false".!
res1: Int = 1

scala> "/bin/true".!
res2: Int = 0

---------------------------------------------------------------------------------------

scala> "uptime".!!
res3: String =
" 17:30:38 up 4 days, 3:41, 5 users, load average: 1.18, 0.97, 0.79
"
---------------------------------------------------------------------------------------

scala> Seq("ls").lines
res4: Stream[String] = Stream(Desktop, ?)

scala> Seq("ls").lines.toList
res5: List[String] = List(Desktop, Documents, Downloads, Music, …)

scala> Seq("ping", "-w", "1", "-c", "1", "google.com").lines
res6: Stream[String] = Stream(PING google.com (173.194.70.103) 56(84) bytes of data., ?)
30/33



                   Process Execution
                                       Magic
scala> def compile(file: String) =
     |   s"ls $file" #&& s"scalac $file" #|| "echo nothing found" lines
compile: (file: String)Stream[String]
31/33



                   Process Execution
                                       Magic
scala> def compile(file: String) =
     |   s"ls $file" #&& s"scalac $file" #|| "echo nothing found" lines
compile: (file: String)Stream[String]

---------------------------------------------------------------------------------------

scala> import java.io.File
import java.io.File

scala> import java.net.URL
import java.net.URL

scala> new URL("http://www.scala-lang.org/") #> new File("/tmp/scala-lang.html") !
res7: Int = 0
32/33



                   Process Execution
                                     Gotchas
scala> Seq("choke").lines
java.io.IOException: Cannot run program "choke": error=2, No such file or directory
33/33




Questions?

More Related Content

What's hot

Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With ScalaMeetu Maltiar
 
Scala parallel-collections
Scala parallel-collectionsScala parallel-collections
Scala parallel-collectionsKnoldus Inc.
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Philip Schwarz
 
Programming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYProgramming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYvikram mahendra
 
Brief tour of psp-std
Brief tour of psp-stdBrief tour of psp-std
Brief tour of psp-stdPaul Phillips
 
Java 8 - project lambda
Java 8 - project lambdaJava 8 - project lambda
Java 8 - project lambdaIvar Østhus
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxEleanor McHugh
 
Java8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfaces
Java8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfacesJava8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfaces
Java8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfacesDirk Detering
 
Data Structures In Scala
Data Structures In ScalaData Structures In Scala
Data Structures In ScalaKnoldus Inc.
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Philip Schwarz
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!priort
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance HaskellJohan Tibell
 
Java 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJava 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJason Swartz
 

What's hot (20)

Sparklyr
SparklyrSparklyr
Sparklyr
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
 
Scala parallel-collections
Scala parallel-collectionsScala parallel-collections
Scala parallel-collections
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
 
Programming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYProgramming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAY
 
Python
PythonPython
Python
 
Scala collections
Scala collectionsScala collections
Scala collections
 
ScalaBlitz
ScalaBlitzScalaBlitz
ScalaBlitz
 
Brief tour of psp-std
Brief tour of psp-stdBrief tour of psp-std
Brief tour of psp-std
 
Java 8 - project lambda
Java 8 - project lambdaJava 8 - project lambda
Java 8 - project lambda
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
 
Java8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfaces
Java8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfacesJava8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfaces
Java8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfaces
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 
Data Structures In Scala
Data Structures In ScalaData Structures In Scala
Data Structures In Scala
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Java 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJava 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason Swartz
 

Viewers also liked

Viewers also liked (10)

How to increase the interest of Engineering among students
How to increase the interest of Engineering among studentsHow to increase the interest of Engineering among students
How to increase the interest of Engineering among students
 
путешествие с нефтью
путешествие с нефтьюпутешествие с нефтью
путешествие с нефтью
 
All About Best Western Wana Riverside Hotel
All About Best Western Wana Riverside HotelAll About Best Western Wana Riverside Hotel
All About Best Western Wana Riverside Hotel
 
علم الحديث رواية ودراية
علم الحديث رواية ودرايةعلم الحديث رواية ودراية
علم الحديث رواية ودراية
 
CONGRESO PROVINCIAL CAM SUR
CONGRESO PROVINCIAL CAM SURCONGRESO PROVINCIAL CAM SUR
CONGRESO PROVINCIAL CAM SUR
 
Rico de coro
Rico de coroRico de coro
Rico de coro
 
Problem solving exercises
Problem solving exercisesProblem solving exercises
Problem solving exercises
 
Mind, Brain and Relationships
Mind, Brain and RelationshipsMind, Brain and Relationships
Mind, Brain and Relationships
 
90 EJERCICIOS PARA PRACTICAR ORTOGRAFÍA Y GRAMÁTICA
90 EJERCICIOS PARA PRACTICAR ORTOGRAFÍA Y GRAMÁTICA 90 EJERCICIOS PARA PRACTICAR ORTOGRAFÍA Y GRAMÁTICA
90 EJERCICIOS PARA PRACTICAR ORTOGRAFÍA Y GRAMÁTICA
 
Modulo V Confección Textil 2016
Modulo  V Confección Textil 2016Modulo  V Confección Textil 2016
Modulo V Confección Textil 2016
 

Similar to Scala Turkiye 2013-02-07 Sunumu

Introduction to parallel and distributed computation with spark
Introduction to parallel and distributed computation with sparkIntroduction to parallel and distributed computation with spark
Introduction to parallel and distributed computation with sparkAngelo Leto
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherColin Eberhardt
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1Giovanni Della Lunga
 
JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APItvaleev
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scalaRaymond Tay
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript ObjectsReem Alattas
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda codePeter Lawrey
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaOstap Andrusiv
 

Similar to Scala Turkiye 2013-02-07 Sunumu (20)

Introduction to parallel and distributed computation with spark
Introduction to parallel and distributed computation with sparkIntroduction to parallel and distributed computation with spark
Introduction to parallel and distributed computation with spark
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better Together
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
 
JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream API
 
Mysql1
Mysql1Mysql1
Mysql1
 
Scala Collections
Scala CollectionsScala Collections
Scala Collections
 
Spark_Documentation_Template1
Spark_Documentation_Template1Spark_Documentation_Template1
Spark_Documentation_Template1
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scala
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
tidyr.pdf
tidyr.pdftidyr.pdf
tidyr.pdf
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda code
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
 
Scala by Luc Duponcheel
Scala by Luc DuponcheelScala by Luc Duponcheel
Scala by Luc Duponcheel
 

Recently uploaded

Chicwish Clothing: A Critical Review of Quality, Fit, and Style
Chicwish Clothing: A Critical Review of Quality, Fit, and StyleChicwish Clothing: A Critical Review of Quality, Fit, and Style
Chicwish Clothing: A Critical Review of Quality, Fit, and Stylechicwishreview
 
Top 10 Moisturising Cream Brands In India - Stelon Biotech
Top 10 Moisturising Cream Brands In India - Stelon BiotechTop 10 Moisturising Cream Brands In India - Stelon Biotech
Top 10 Moisturising Cream Brands In India - Stelon BiotechStelon Biotech
 
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...rajveerescorts2022
 
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your DoorstepCall girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstepmitaliverma221
 
❤️Amritsar Call Girls☎️9815674956☎️ Call Girl service in Amritsar☎️ Amritsar ...
❤️Amritsar Call Girls☎️9815674956☎️ Call Girl service in Amritsar☎️ Amritsar ...❤️Amritsar Call Girls☎️9815674956☎️ Call Girl service in Amritsar☎️ Amritsar ...
❤️Amritsar Call Girls☎️9815674956☎️ Call Girl service in Amritsar☎️ Amritsar ...Sheetaleventcompany
 
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...Nitya salvi
 
Introduction to Fashion Designing for all
Introduction to Fashion Designing for allIntroduction to Fashion Designing for all
Introduction to Fashion Designing for allMuhammadDanishAwan1
 
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime TumkurTumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkurmeghakumariji156
 
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...Sheetaleventcompany
 
📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call Girls📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call GirlsNitya salvi
 
UNIVERSAL HUMAN VALUES -Harmony in the Human Being
UNIVERSAL HUMAN VALUES -Harmony in the Human BeingUNIVERSAL HUMAN VALUES -Harmony in the Human Being
UNIVERSAL HUMAN VALUES -Harmony in the Human BeingChandrakantDivate1
 
Call Girls Service In Zirakpur ❤️🍑 7837612180 👄🫦Independent Escort Service Zi...
Call Girls Service In Zirakpur ❤️🍑 7837612180 👄🫦Independent Escort Service Zi...Call Girls Service In Zirakpur ❤️🍑 7837612180 👄🫦Independent Escort Service Zi...
Call Girls Service In Zirakpur ❤️🍑 7837612180 👄🫦Independent Escort Service Zi...Sheetaleventcompany
 
Style Victorious Cute Outfits for Winners
Style Victorious Cute Outfits for WinnersStyle Victorious Cute Outfits for Winners
Style Victorious Cute Outfits for Winnersolva0212
 
Payal Mehta 9867746289, Escorts Service Near The Taj Mahal Palace Colaba
Payal Mehta 9867746289, Escorts Service Near The Taj Mahal Palace ColabaPayal Mehta 9867746289, Escorts Service Near The Taj Mahal Palace Colaba
Payal Mehta 9867746289, Escorts Service Near The Taj Mahal Palace ColabaPooja Nehwal
 
9867746289 - Payal Mehta Book Call Girls in Versova and escort services 24x7
9867746289 - Payal Mehta Book Call Girls in Versova and escort services 24x79867746289 - Payal Mehta Book Call Girls in Versova and escort services 24x7
9867746289 - Payal Mehta Book Call Girls in Versova and escort services 24x7Pooja Nehwal
 
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service ZirakpurZirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service ZirakpurSheetaleventcompany
 
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime TirunelveliTirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelvelimeghakumariji156
 
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...rajveermohali2022
 
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...Sheetaleventcompany
 
Tinted Sunscreen For Soft and Smooth Skin
Tinted Sunscreen For Soft and Smooth SkinTinted Sunscreen For Soft and Smooth Skin
Tinted Sunscreen For Soft and Smooth SkinUniqaya Lifestyle
 

Recently uploaded (20)

Chicwish Clothing: A Critical Review of Quality, Fit, and Style
Chicwish Clothing: A Critical Review of Quality, Fit, and StyleChicwish Clothing: A Critical Review of Quality, Fit, and Style
Chicwish Clothing: A Critical Review of Quality, Fit, and Style
 
Top 10 Moisturising Cream Brands In India - Stelon Biotech
Top 10 Moisturising Cream Brands In India - Stelon BiotechTop 10 Moisturising Cream Brands In India - Stelon Biotech
Top 10 Moisturising Cream Brands In India - Stelon Biotech
 
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...
Call Girls In Mohali ☎ 9915851334☎ Just Genuine Call Call Girls Mohali 🧿Elite...
 
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your DoorstepCall girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
 
❤️Amritsar Call Girls☎️9815674956☎️ Call Girl service in Amritsar☎️ Amritsar ...
❤️Amritsar Call Girls☎️9815674956☎️ Call Girl service in Amritsar☎️ Amritsar ...❤️Amritsar Call Girls☎️9815674956☎️ Call Girl service in Amritsar☎️ Amritsar ...
❤️Amritsar Call Girls☎️9815674956☎️ Call Girl service in Amritsar☎️ Amritsar ...
 
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
 
Introduction to Fashion Designing for all
Introduction to Fashion Designing for allIntroduction to Fashion Designing for all
Introduction to Fashion Designing for all
 
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime TumkurTumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
 
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
 
📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call Girls📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call Girls
 
UNIVERSAL HUMAN VALUES -Harmony in the Human Being
UNIVERSAL HUMAN VALUES -Harmony in the Human BeingUNIVERSAL HUMAN VALUES -Harmony in the Human Being
UNIVERSAL HUMAN VALUES -Harmony in the Human Being
 
Call Girls Service In Zirakpur ❤️🍑 7837612180 👄🫦Independent Escort Service Zi...
Call Girls Service In Zirakpur ❤️🍑 7837612180 👄🫦Independent Escort Service Zi...Call Girls Service In Zirakpur ❤️🍑 7837612180 👄🫦Independent Escort Service Zi...
Call Girls Service In Zirakpur ❤️🍑 7837612180 👄🫦Independent Escort Service Zi...
 
Style Victorious Cute Outfits for Winners
Style Victorious Cute Outfits for WinnersStyle Victorious Cute Outfits for Winners
Style Victorious Cute Outfits for Winners
 
Payal Mehta 9867746289, Escorts Service Near The Taj Mahal Palace Colaba
Payal Mehta 9867746289, Escorts Service Near The Taj Mahal Palace ColabaPayal Mehta 9867746289, Escorts Service Near The Taj Mahal Palace Colaba
Payal Mehta 9867746289, Escorts Service Near The Taj Mahal Palace Colaba
 
9867746289 - Payal Mehta Book Call Girls in Versova and escort services 24x7
9867746289 - Payal Mehta Book Call Girls in Versova and escort services 24x79867746289 - Payal Mehta Book Call Girls in Versova and escort services 24x7
9867746289 - Payal Mehta Book Call Girls in Versova and escort services 24x7
 
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service ZirakpurZirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
 
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime TirunelveliTirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
 
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
 
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
 
Tinted Sunscreen For Soft and Smooth Skin
Tinted Sunscreen For Soft and Smooth SkinTinted Sunscreen For Soft and Smooth Skin
Tinted Sunscreen For Soft and Smooth Skin
 

Scala Turkiye 2013-02-07 Sunumu

  • 1. 1/33 TÜRKİYE String Interpolation presenter Volkan Yazıcı Streams https://twitter.com/yazicivo Regular Expressions http://vyazici.blogspot.com http://github.com/vy Process Execution http://web.itu.edu.tr/~yazicivo/ https://groups.google.com/forum/?fromgroups=#!forum/scala-turkiye 2013-02-07
  • 2. 2/33 Implicit Classes simplify the creation of classes which provide extension methods to another type. http://docs.scala-lang.org/sips/pending/implicit-classes.html
  • 3. 3/33 Implicit Classes Basics scala> implicit class MyString(val str: String) { | def quote: String = "'" + str + "'" | } defined class MyString scala> println("abc") abc scala> println("abc".quote) 'abc'
  • 4. 4/33 Implicit Classes Basics scala> implicit class MyString(val str: String) { | def quote: String = "'" + str + "'" | } defined class MyString scala> println("abc") abc scala> println("abc".quote) 'abc' --------------------------------------------------------------------------------------- scala> implicit class MyInt(val n: Int) { | def factorial: Int = { | require(n >= 0) | if (n < 2) 1 | else n * (n-1).factorial | } | } defined class MyInt scala> 5.factorial res3: Int = 120
  • 5. 5/33 String Interpolation allows users to embed variable references directly in processed string literals. http://www.scala-lang.org/node/258
  • 6. 6/33 String Interpolation Basics scala> val (str, num) = ("Walter White", 0.128F) str: String = Walter White num: Float = 0.128
  • 7. 7/33 String Interpolation Basics scala> val (str, num) = ("Walter White", 0.128F) str: String = Walter White num: Float = 0.128 --------------------------------------------------------------------------------------- scala> println(s"str: $str, num: $num") str: Walter White, num: 0.128
  • 8. 8/33 String Interpolation Basics scala> val (str, num) = ("Walter White", 0.128F) str: String = Walter White num: Float = 0.128 --------------------------------------------------------------------------------------- scala> println(s"str: $str, num: $num") str: Walter White, num: 0.128 --------------------------------------------------------------------------------------- scala> println(s"1 + 1 = ${1 + 1}”) 1 + 1 = 2 scala> println(s"2 * $num = ${2 * num}”) 2 * 0.128 = 0.256
  • 9. 9/33 String Interpolation Basics scala> val (str, num) = ("Walter White", 0.128F) str: String = Walter White num: Float = 0.128 --------------------------------------------------------------------------------------- scala> println(s"str: $str, num: $num") str: Walter White, num: 0.128 --------------------------------------------------------------------------------------- scala> println(s"1 + 1 = ${1 + 1}”) 1 + 1 = 2 scala> println(s"2 * $num = ${2 * num}”) 2 * 0.128 = 0.256 --------------------------------------------------------------------------------------- scala> println(f"num: $num%.2f") Num: 0.13
  • 10. 10/33 String Interpolation Basics scala> val (str, num) = ("Walter White", 0.128F) str: String = Walter White num: Float = 0.128 --------------------------------------------------------------------------------------- scala> println(s"str: $str, num: $num") str: Walter White, num: 0.128 --------------------------------------------------------------------------------------- scala> println(s"1 + 1 = ${1 + 1}”) 1 + 1 = 2 scala> println(s"2 * $num = ${2 * num}”) 2 * 0.128 = 0.256 --------------------------------------------------------------------------------------- scala> println(f"num: $num%.2f") Num: 0.13 --------------------------------------------------------------------------------------- scala> println(raw"anb u0040") anb @
  • 11. 11/33 String Interpolation Internals Compiler transformation: id”string” ↔ StringContext(“string”).id() Existing StringContext methods: s, f, and raw. We can extend StringContext using implicit classes.
  • 12. 12/33 String Interpolation Extending scala> implicit class MyStringContext(val sc: StringContext) { | def q(args: Any*): String = s"args: '$args', parts: '$sc.parts'" | } defined class MyStringContext scala> println(q"abc ${1+1} def") args: 'WrappedArray(2)', parts: 'StringContext(WrappedArray(abc , def)).parts'
  • 13. 13/33 A Stream is like a list except that its elements are computed lazily. http://www.scala-lang.org/api/current/scala/collection/immutable/Stream.html
  • 14. 14/33 Streams Basics scala> Stream.cons(1, Stream.empty) res0: Stream.Cons[Int] = Stream(1, ?) scala> Stream.cons(1, Stream.empty): Stream[Int] res1: Stream[Int] = Stream(1, ?) scala> Stream.cons(1, Stream.empty).toList res2: List[Int] = List(1) scala> Stream.cons(1, Stream.cons(2, Stream.empty)).toList res3: List[Int] = List(1, 2)
  • 15. 15/33 Streams Basics scala> Stream.cons(1, Stream.empty) res0: Stream.Cons[Int] = Stream(1, ?) scala> Stream.cons(1, Stream.empty): Stream[Int] res1: Stream[Int] = Stream(1, ?) scala> Stream.cons(1, Stream.empty).toList res2: List[Int] = List(1) scala> Stream.cons(1, Stream.cons(2, Stream.empty)).toList res3: List[Int] = List(1, 2) --------------------------------------------------------------------------------------- scala> def integers(n: Int): Stream[Int] = Stream.cons(n, integers(n+1)) integers: (from: Int)Stream[Int] scala> integers(0) res4: Stream[Int] = Stream(0, ?) scala> integers(0).take(10) res5: Stream[Int] = Stream(0, ?) scala> integers(0).take(10).toList res6: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
  • 16. 16/33 Streams Usage scala> def evenNumbers: Stream[Int] = integers(0).filter(_ % 2 == 0) evenNumbers: ()Stream[Int] scala> evenNumbers.take(10).toList res7: List[Int] = List(0, 2, 4, 6, 8, 10, 12, 14, 16, 18)
  • 17. 17/33 Streams Usage scala> def evenNumbers: Stream[Int] = integers(0).filter(_ % 2 == 0) evenNumbers: ()Stream[Int] scala> evenNumbers.take(10).toList res7: List[Int] = List(0, 2, 4, 6, 8, 10, 12, 14, 16, 18) --------------------------------------------------------------------------------------- scala> Stream.continually(math.random).take(3).toList res8: List[Double] = List(0.5932830094101399, 0.4377639789538802, 0.4522513999390704)
  • 18. 18/33 Streams Usage scala> def evenNumbers: Stream[Int] = integers(0).filter(_ % 2 == 0) evenNumbers: ()Stream[Int] scala> evenNumbers.take(10).toList res7: List[Int] = List(0, 2, 4, 6, 8, 10, 12, 14, 16, 18) --------------------------------------------------------------------------------------- scala> Stream.continually(math.random).take(3).toList res8: List[Double] = List(0.5932830094101399, 0.4377639789538802, 0.4522513999390704) --------------------------------------------------------------------------------------- scala> Stream.continually(List(1,2,3)).flatten.take(8).toList res9: List[Int] = List(1, 2, 3, 1, 2, 3, 1, 2)
  • 19. 19/33 Streams Recursion [1/2] scala> def fibonacci: Stream[Int] = 1 #:: 1 #:: fibonacci.zip(fibonacci.tail).map { case (x, y) => x + y } fibonacci: Stream[Int] scala> fibonacci.take(10).toList res8: List[Int] = List(1, 1, 2, 3, 5, 8, 13, 21, 34, 55)
  • 20. 20/33 Streams Recursion [2/2] scala> def primes(implicit n: Int = 2): Stream[Int] = integers(n) match { case x #:: xs => x #:: primes(x+1).filter(_ % x != 0) } primes: (implicit n: Int)Stream[Int] scala> primes.take(10).toList res17: List[Int] = List(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
  • 21. 21/33 Streams Gotchas scala> def naturalNumbers: Stream[Int] = integers(0) naturalNumbers: ()Stream[Int] scala> val naturalNumbers: Stream[Int] = integers(0) naturalNumbers: Stream[Int] = Stream(0, ?) scala> lazy val naturalNumbers: Stream[Int] = integers(0) naturalNumbers: Stream[Int] = <lazy>
  • 22. 22/33 Regular Expressions http://www.scala-lang.org/api/current/index.html#scala.util.matching.Regex
  • 23. 23/33 Regular Expressions Basics scala> "0xDeadBeef" matches "0x[0-9a-fA-F]+" res1: Boolean = true scala> "abc 0x12 def" matches "0x[0-9a-fA-F]+" res2: Boolean = false
  • 24. 24/33 Regular Expressions Basics scala> "0xDeadBeef" matches "0x[0-9a-fA-F]+" res1: Boolean = true scala> "abc 0x12 def" matches "0x[0-9a-fA-F]+" res2: Boolean = false --------------------------------------------------------------------------------------- scala> val dateRegex = "([0-9]{4})-([0-9]{2})-([0-9]{2})".r hexregex: scala.util.matching.Regex = ([0-9]{4})-([0-9]{2})-([0-9]{2}) scala> dateRegex findFirstIn "2013-04-08" match { | case Some(dateRegex(y, m, n)) => s"y: $y, m: $m, n: $n" | case None => "invalid date" | } res3: String = y: 2013, m: 04, n: 08 scala> dateRegex findAllIn "2013-04-08 2012-05-07" map { | case dateRegex(y, m, n) => (y, m, n) | } toList res4: List[(String, String, String)] = List((2013,04,08), (2012,05,07))
  • 25. 25/33 Process Execution http://www.scala-lang.org/api/current/index.html#scala.sys.process.package
  • 26. 26/33 Process Execution Basics scala> import scala.sys.process._ import scala.sys.process._
  • 27. 27/33 Process Execution Basics scala> import scala.sys.process._ import scala.sys.process._ --------------------------------------------------------------------------------------- scala> "/bin/false".! res1: Int = 1 scala> "/bin/true".! res2: Int = 0
  • 28. 28/33 Process Execution Basics scala> import scala.sys.process._ import scala.sys.process._ --------------------------------------------------------------------------------------- scala> "/bin/false".! res1: Int = 1 scala> "/bin/true".! res2: Int = 0 --------------------------------------------------------------------------------------- scala> "uptime".!! res3: String = " 17:30:38 up 4 days, 3:41, 5 users, load average: 1.18, 0.97, 0.79 "
  • 29. 29/33 Process Execution Basics scala> import scala.sys.process._ import scala.sys.process._ --------------------------------------------------------------------------------------- scala> "/bin/false".! res1: Int = 1 scala> "/bin/true".! res2: Int = 0 --------------------------------------------------------------------------------------- scala> "uptime".!! res3: String = " 17:30:38 up 4 days, 3:41, 5 users, load average: 1.18, 0.97, 0.79 " --------------------------------------------------------------------------------------- scala> Seq("ls").lines res4: Stream[String] = Stream(Desktop, ?) scala> Seq("ls").lines.toList res5: List[String] = List(Desktop, Documents, Downloads, Music, …) scala> Seq("ping", "-w", "1", "-c", "1", "google.com").lines res6: Stream[String] = Stream(PING google.com (173.194.70.103) 56(84) bytes of data., ?)
  • 30. 30/33 Process Execution Magic scala> def compile(file: String) = | s"ls $file" #&& s"scalac $file" #|| "echo nothing found" lines compile: (file: String)Stream[String]
  • 31. 31/33 Process Execution Magic scala> def compile(file: String) = | s"ls $file" #&& s"scalac $file" #|| "echo nothing found" lines compile: (file: String)Stream[String] --------------------------------------------------------------------------------------- scala> import java.io.File import java.io.File scala> import java.net.URL import java.net.URL scala> new URL("http://www.scala-lang.org/") #> new File("/tmp/scala-lang.html") ! res7: Int = 0
  • 32. 32/33 Process Execution Gotchas scala> Seq("choke").lines java.io.IOException: Cannot run program "choke": error=2, No such file or directory