350 lines
6.3 KiB
Plaintext
350 lines
6.3 KiB
Plaintext
|
################################################################
|
||
|
# © Copyright 2011 Konstantin Gorodinskiy. All Rights Reserved.#
|
||
|
# Do What The Fuck You Want To Public License, Version 2. #
|
||
|
# See http://sam.zoy.org/wtfpl/COPYING for more details. #
|
||
|
################################################################
|
||
|
# Scala lang
|
||
|
#if
|
||
|
snippet if
|
||
|
if(${1:obj}) {
|
||
|
${2:/* code */}
|
||
|
}
|
||
|
#if not
|
||
|
snippet ifn
|
||
|
if(!${1:obj}) {
|
||
|
${2:/* code */}
|
||
|
}
|
||
|
#if-else
|
||
|
snippet ifel
|
||
|
if(${1:obj}) {
|
||
|
${2:/* code */}
|
||
|
} else {
|
||
|
${3:/* code */}
|
||
|
}
|
||
|
#if-else-if
|
||
|
snippet ifelif
|
||
|
if(${1:obj}) {
|
||
|
${2:/* code */}
|
||
|
} else if(${3:obj}) {
|
||
|
${4:/* code */}
|
||
|
}
|
||
|
#while loop
|
||
|
snippet while
|
||
|
while (${1:obj}) {
|
||
|
${2:/* code */}
|
||
|
}
|
||
|
#for loop(classic)
|
||
|
snippet for
|
||
|
for (${1:item} <- ${2:obj}) {
|
||
|
${3:/* code */}
|
||
|
}
|
||
|
#for loop(indexed)
|
||
|
snippet fori
|
||
|
for (${1:i} <- ${2:0} to ${3:obj}.length) {
|
||
|
${4:/* code */}
|
||
|
}
|
||
|
#exceptions
|
||
|
snippet try
|
||
|
try {
|
||
|
${1:/* code */}
|
||
|
} catch {
|
||
|
case e: FileNotFoundException => ${2:/* code */}
|
||
|
case e: IOException => ${3:/* code */}
|
||
|
} finally {
|
||
|
${4:/* code */}
|
||
|
}
|
||
|
#match
|
||
|
snippet match
|
||
|
${1: obj} match {
|
||
|
case ${2:e} => ${3:/* code */}
|
||
|
case _ => ${4:/* code */}
|
||
|
}
|
||
|
#case
|
||
|
snippet case
|
||
|
case ${1:value} => ${2:/* code */}
|
||
|
############################
|
||
|
# methods and arguments
|
||
|
#
|
||
|
#arg
|
||
|
snippet arg
|
||
|
${1:a}: ${2:T}${3:, arg}
|
||
|
#args
|
||
|
snippet args
|
||
|
${1:args}: ${2:T}*
|
||
|
#def
|
||
|
snippet def
|
||
|
def ${1:name}(${2:arg}) = ${3:}
|
||
|
#private def
|
||
|
snippet prdef
|
||
|
private def ${1:name}(${2:arg}) = ${3:}
|
||
|
#override def
|
||
|
snippet ovdef
|
||
|
override def ${1:name}(${2:arg}) = ${3:}
|
||
|
#first class function(see scalabook p 188)
|
||
|
snippet fcf
|
||
|
(${1:a}: ${2:T}) => $1 ${3:/* code */}
|
||
|
snippet =>
|
||
|
${1:name} => ${2:/* code */}
|
||
|
#recursion
|
||
|
snippet rec
|
||
|
def ${1:name}(${2:arg}) =
|
||
|
if($2) $2
|
||
|
else $1($2)
|
||
|
#curried method
|
||
|
snippet crdef
|
||
|
def ${1:name}(${2:arg})(${3:arg}) = ${4:}
|
||
|
#main method
|
||
|
#check validity of T
|
||
|
snippet main
|
||
|
def main(args: Array[String]):${1:T} = ${2:}
|
||
|
############################
|
||
|
# basic types(general purpose)
|
||
|
# you might want to use basic types snippets
|
||
|
|
||
|
#1
|
||
|
snippet T Double
|
||
|
dbl
|
||
|
#2
|
||
|
snippet T Int
|
||
|
int
|
||
|
#3
|
||
|
snippet T Long
|
||
|
lng
|
||
|
#4
|
||
|
snippet T Char
|
||
|
chr
|
||
|
#5
|
||
|
snippet T String
|
||
|
str
|
||
|
#6
|
||
|
snippet T Array
|
||
|
arr
|
||
|
#7
|
||
|
snippet T Buffer
|
||
|
buf
|
||
|
#8
|
||
|
snippet T List
|
||
|
list
|
||
|
#9
|
||
|
snippet T Tuple
|
||
|
tpl
|
||
|
#10
|
||
|
snippet T Set
|
||
|
set
|
||
|
#11
|
||
|
snippet T Map
|
||
|
map
|
||
|
#12
|
||
|
snippet T HashSet
|
||
|
hset
|
||
|
#13
|
||
|
snippet T HashMap
|
||
|
hmap
|
||
|
#14
|
||
|
snippet T Boolean
|
||
|
bool
|
||
|
#end
|
||
|
|
||
|
#named snippets for types
|
||
|
snippet bool
|
||
|
Boolean
|
||
|
snippet anyr
|
||
|
AnyRef
|
||
|
snippet dbl
|
||
|
Double
|
||
|
snippet int
|
||
|
Int
|
||
|
snippet str
|
||
|
String
|
||
|
snippet chr
|
||
|
Char
|
||
|
snippet lng
|
||
|
Long
|
||
|
snippet arr
|
||
|
Array${1:[T]}${2:()}
|
||
|
snippet buf
|
||
|
Buffer${1:[T]}${2:()}
|
||
|
snippet list
|
||
|
List${1:[T]}${2:()}
|
||
|
snippet tpl
|
||
|
Tuple${1:2}[${2:T},${3:T}]
|
||
|
snippet set
|
||
|
Set${1:[T]}${2:()}
|
||
|
snippet hset
|
||
|
HashSet${1:[T]}${2:()}
|
||
|
snippet mhset
|
||
|
mutable.HashSet${1:[T]}${2:()}
|
||
|
#for maps
|
||
|
snippet keyval
|
||
|
${1:key}->${2:val}${3:, keyval}
|
||
|
snippet map
|
||
|
Map[${1:T},${2:T}]${3:(keyval)}
|
||
|
snippet hmap
|
||
|
HashMap[${1:T},${2:T}]${3:(keyval)}
|
||
|
snippet mmap
|
||
|
mutable.Map[${1:T},${2:T}]${3:(keyval)}
|
||
|
snippet mhmap
|
||
|
mutable.HashMap[${1:T},${2:T}]${3:(keyval)}
|
||
|
#TODO add TreeMap and TreeSet
|
||
|
#asInstanceOf[]
|
||
|
snippet as
|
||
|
${1:name}.asInstanceOf[${2:T}]
|
||
|
#isInstanceOf[]
|
||
|
${1:name}.isInstanceOf[${2:T}]
|
||
|
#end
|
||
|
#collections methods
|
||
|
|
||
|
#scope() with one arg
|
||
|
snippet (a
|
||
|
(${1:a} => ${2:/* code */})
|
||
|
#scope() with two args
|
||
|
snippet {(
|
||
|
{(${1:a},${2:b}) =>
|
||
|
${3:/* code */}
|
||
|
}
|
||
|
#filter
|
||
|
snippet filter
|
||
|
${1:name}.filter (a
|
||
|
#map function
|
||
|
snippet mapf
|
||
|
${1:name}.map (a
|
||
|
#flatmap
|
||
|
snippet flatmap
|
||
|
${1:name}.flatMap${2:[T]}(a
|
||
|
#fold left
|
||
|
snippet fldl
|
||
|
${1:name}.foldLeft(${2:first}) {(
|
||
|
#fold right
|
||
|
snippet fldr
|
||
|
${1:name}.foldRight(${2:first}) {(
|
||
|
#fold left operator(if u wanna reduce readability of ur code)
|
||
|
#use wildcard symbols
|
||
|
snippet /:
|
||
|
(${1:first}/:${2:name})(${3:/* code */})
|
||
|
#fold right operator
|
||
|
snippet :\
|
||
|
(${1:first}:\${2:name})(${3:/* code */})
|
||
|
#reduce left
|
||
|
snippet redl
|
||
|
${1:name}.reduceLeft[${2:T}] {(
|
||
|
#reduce right
|
||
|
snippet redr
|
||
|
${1:name}.reduceRight[${2:T}] {(
|
||
|
#zipWithIndex(safe way).
|
||
|
#see http://daily-scala.blogspot.com/2010/05/zipwithindex.html
|
||
|
snippet zipwi
|
||
|
${1:name}.view.zipWithIndex
|
||
|
#split
|
||
|
snippet spl
|
||
|
${1:name}.split("${2:,}")
|
||
|
#end
|
||
|
snippet val
|
||
|
val ${1:name}${2:: T} = ${3:value}
|
||
|
snippet var
|
||
|
var ${1:name}${2:: T} = ${3:value}
|
||
|
############################
|
||
|
# classes
|
||
|
#
|
||
|
#extends
|
||
|
snippet extends
|
||
|
extends ${1:what}
|
||
|
#with
|
||
|
snippet with
|
||
|
with ${1:what}${2: with}
|
||
|
#auxiliary constructor(a. this)
|
||
|
snippet athis
|
||
|
def this(arg) = this(arg)
|
||
|
#abstract class
|
||
|
snippet abstract
|
||
|
abstract class ${1:name}${2:(arg)}${3: extends }${4: with} {
|
||
|
${5:override def toString = "$1"}
|
||
|
${6:/* code */}
|
||
|
}
|
||
|
#class
|
||
|
snippet class
|
||
|
class ${1:name}${2:(arg)}${3: extends }${4: with} {
|
||
|
${5:override def toString = "$1"}
|
||
|
${6:/* code */}
|
||
|
}
|
||
|
#object
|
||
|
snippet object
|
||
|
object ${1:name}${2:(arg)}${3: extends }${4: with} ${5:}
|
||
|
#trait
|
||
|
snippet trait
|
||
|
trait ${1:name}${2: extends }${3: with} {
|
||
|
${4:}
|
||
|
}
|
||
|
#class with trait Ordered(page 265)
|
||
|
snippet ordered
|
||
|
class ${1:name}${2:(arg)} extends Ordered[$1] ${3: with} {
|
||
|
${4:override def toString = "$1"}
|
||
|
def compare(that: $1) = ${5:this - that}
|
||
|
${6:/* code */}
|
||
|
}
|
||
|
#case class
|
||
|
snippet casecl
|
||
|
case class ${1:name}${2:(arg)}${3: extends }${4: with} ${5:}
|
||
|
############################
|
||
|
# testing
|
||
|
#
|
||
|
#scalatest imports
|
||
|
snippet scalatest
|
||
|
${1:import org.scalatest.Suite}
|
||
|
${2:import org.scalatest.FunSuite}
|
||
|
#assert
|
||
|
snippet assert
|
||
|
assert(${1:a}==${2:b})
|
||
|
#ensuring(p 296)
|
||
|
snippet ensuring
|
||
|
ifel ensuring(${1:a}==${2:b})
|
||
|
#expect
|
||
|
snippet expect
|
||
|
expect(${1:what}) {
|
||
|
#intercept
|
||
|
snippet intercept
|
||
|
intercept[${1:IllegalArgumentException}] {
|
||
|
#test
|
||
|
snippet test
|
||
|
test("${1:description}") {
|
||
|
#suite
|
||
|
snippet suite
|
||
|
class ${1:name} extends Suite {
|
||
|
def test() {
|
||
|
}
|
||
|
#funsuite
|
||
|
snippet fsuite
|
||
|
class ${1:name} extends FunSuite {
|
||
|
test("${2:description}") {
|
||
|
}
|
||
|
############################
|
||
|
# SBT
|
||
|
#
|
||
|
snippet webproject
|
||
|
import sbt._
|
||
|
|
||
|
class ${1:Name}(info: ProjectInfo) extends DefaultWebProject(info) {
|
||
|
val liftVersion = "${2:2.3}"
|
||
|
|
||
|
override def libraryDependencies = Set(
|
||
|
|
||
|
) ++ super.libraryDependencies
|
||
|
|
||
|
val snapshots = ScalaToolsSnapshots
|
||
|
}
|
||
|
#depencies
|
||
|
snippet liftjar
|
||
|
"net.liftweb" %% "${1:lib}" % liftVersion % "compile->default",
|
||
|
snippet jettyjar
|
||
|
"org.mortbay.jetty" % "jetty" % "${1:version}" % "test->default",
|
||
|
############################
|
||
|
# Lift
|
||
|
#
|
||
|
#lift imports
|
||
|
snippet liftimports
|
||
|
import _root_.net.liftweb.http._
|
||
|
import S._
|
||
|
import _root_.net.liftweb.util._
|
||
|
import Helpers._
|
||
|
import _root_.scala.xml._
|
||
|
#TODO LIFT,SBT,WEB.XML,HTML snippets
|