This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | new Iterator[String] { | |
| def hasNext = resultSet.next() | |
| def next() = resultSet.getString(1) | |
| }.toStream | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | object x { | |
| // stream a sql query | |
| def sql( str:String ):Stream[ResultSet] = withStatement { s => | |
| val rs = s executeQuery str | |
| new Iterator[ResultSet] { def hasNext = rs.next ; def next = rs }.toStream | |
| } | |
| // loan a sql statement | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | println(scala.io.Source.fromFile("some.txt").mkString) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | implicit def intWithTimes(n: Int) = new { | |
| def times(f: => Unit) = 1 to n foreach {_ => f} | |
| } | |
| 5 times { | |
| println("Hello World") | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | trait ReflectionSugars{ | |
| import scala.reflect.runtime.{universe => ru} | |
| private lazy val universeMirror = ru.runtimeMirror(getClass.getClassLoader) | |
| def companionOf[T](implicit tt: ru.TypeTag[T]) = { | |
| val companionMirror = universeMirror.reflectModule(ru.typeOf[T].typeSymbol.companionSymbol.asModule) | |
| companionMirror.instance | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $ scala -Dscala.color | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | scala> val sqlc = new org.apache.spark.sql.SQLContext(sc) | |
| scala> import sqlc.implicits._ //to implicitly convert an RDD to a DataFrame | |
| scala> val df1 = sqlc.load("/home/....json","json") | |
| scala> df1.printSchema | |
| scala> df1.select("name").show | |
| scala> df1.select("name", df1("age") + 1).show | |
| scala> df1.filter(df1("age") > 10).show | |
| scala> df1.groupBy("age").count().show | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def unless(expr: Boolean)(perform: ()=>Unit) { if(!expr) perform() } | |
| unless(6 == 5) { ()=>println("Hello world") } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | case object CONNECTION { | |
| def unary_! = DISCONNECTION | |
| def REMOVE = DISCONNECTION | |
| } | |
| case object DISCONNECTION | |
| println(!CONNECTION == DISCONNECTION) //true | |
| println((CONNECTION REMOVE) == DISCONNECTION) //true | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ; A REPL-based, annotated Seesaw tutorial | |
| ; Please visit https://github.com/daveray/seesaw for more info | |
| ; | |
| ; This is a very basic intro to Seesaw, a Clojure UI toolkit. It covers | |
| ; Seesaw's basic features and philosophy, but only scratches the surface | |
| ; of what's available. It only assumes knowledge of Clojure. No Swing or | |
| ; Java experience is needed. | |
| ; | |
| ; This material was first presented in a talk at @CraftsmanGuild in | |
| ; Ann Arbor, MI. | 
OlderNewer