2013-04-13 13:45:21 -04:00
|
|
|
################################################################
|
|
|
|
# © 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
|
2014-10-14 09:30:33 -04:00
|
|
|
if (${1})
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-04-13 13:45:21 -04:00
|
|
|
#if not
|
|
|
|
snippet ifn
|
2014-10-14 09:30:33 -04:00
|
|
|
if (!${1})
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-04-13 13:45:21 -04:00
|
|
|
#if-else
|
2013-07-17 19:06:05 -04:00
|
|
|
snippet ife
|
2014-10-14 09:30:33 -04:00
|
|
|
if (${1})
|
2017-02-11 08:01:38 -05:00
|
|
|
${2:${VISUAL}}
|
2014-10-14 09:30:33 -04:00
|
|
|
else
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
#if-else-if
|
|
|
|
snippet ifelif
|
2014-10-14 09:30:33 -04:00
|
|
|
if (${1})
|
2017-02-11 08:01:38 -05:00
|
|
|
${2:${VISUAL}}
|
2014-10-14 09:30:33 -04:00
|
|
|
else if (${3})
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-07-17 19:06:05 -04:00
|
|
|
snippet eif
|
2014-10-14 09:30:33 -04:00
|
|
|
else if (${3})
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-04-13 13:45:21 -04:00
|
|
|
#while loop
|
2013-11-16 14:45:48 -05:00
|
|
|
snippet wh
|
2013-04-13 13:45:21 -04:00
|
|
|
while (${1:obj}) {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#for loop(classic)
|
|
|
|
snippet for
|
|
|
|
for (${1:item} <- ${2:obj}) {
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#for loop(indexed)
|
|
|
|
snippet fori
|
|
|
|
for (${1:i} <- ${2:0} to ${3:obj}.length) {
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
2014-10-31 17:30:24 -04:00
|
|
|
#for comprehension
|
|
|
|
snippet fory
|
|
|
|
for {
|
|
|
|
${1:item} <- ${2:obj}
|
|
|
|
} yield ${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
#exceptions
|
|
|
|
snippet try
|
|
|
|
try {
|
2017-02-11 08:01:38 -05:00
|
|
|
${1:${VISUAL}}
|
2013-04-13 13:45:21 -04:00
|
|
|
} catch {
|
2013-07-17 19:06:05 -04:00
|
|
|
case e: FileNotFoundException => ${2}
|
|
|
|
case e: IOException => ${3}
|
2013-04-13 13:45:21 -04:00
|
|
|
} finally {
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#match
|
2017-12-13 09:05:24 -05:00
|
|
|
snippet mat
|
|
|
|
${1:${VISUAL}} match {
|
|
|
|
case ${2} => ${0}
|
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet match
|
|
|
|
${1: obj} match {
|
2013-07-17 19:06:05 -04:00
|
|
|
case ${2:e} => ${3}
|
2013-11-16 14:45:48 -05:00
|
|
|
case _ => ${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#case
|
|
|
|
snippet case
|
2017-12-13 09:05:24 -05:00
|
|
|
case ${1:${VISUAL}} => ${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
############################
|
|
|
|
# methods and arguments
|
|
|
|
#
|
|
|
|
#arg
|
|
|
|
snippet arg
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:a}: ${2:T}${0:, arg}
|
2013-04-13 13:45:21 -04:00
|
|
|
#args
|
|
|
|
snippet args
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:args}: ${0:T}*
|
2013-04-13 13:45:21 -04:00
|
|
|
#def
|
|
|
|
snippet def
|
2013-11-16 14:45:48 -05:00
|
|
|
def ${1:name}(${2:arg}) = ${0:}
|
2013-04-13 13:45:21 -04:00
|
|
|
#private def
|
|
|
|
snippet prdef
|
2013-11-16 14:45:48 -05:00
|
|
|
private def ${1:name}(${2:arg}) = ${0:}
|
2013-04-13 13:45:21 -04:00
|
|
|
#override def
|
|
|
|
snippet ovdef
|
2013-11-16 14:45:48 -05:00
|
|
|
override def ${1:name}(${2:arg}) = ${0:}
|
2013-04-13 13:45:21 -04:00
|
|
|
#first class function(see scalabook p 188)
|
|
|
|
snippet fcf
|
2013-11-16 14:45:48 -05:00
|
|
|
(${1:a}: ${2:T}) => $1 ${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet =>
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:name} => ${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
#recursion
|
|
|
|
snippet rec
|
2013-11-16 14:45:48 -05:00
|
|
|
def ${1:name}(${0:arg}) =
|
2013-04-13 13:45:21 -04:00
|
|
|
if($2) $2
|
|
|
|
else $1($2)
|
|
|
|
#curried method
|
|
|
|
snippet crdef
|
2013-11-16 14:45:48 -05:00
|
|
|
def ${1:name}(${2:arg})(${3:arg}) = ${0:}
|
2013-04-13 13:45:21 -04:00
|
|
|
#main method
|
|
|
|
#check validity of T
|
|
|
|
snippet main
|
2013-11-16 14:45:48 -05:00
|
|
|
def main(args: Array[String]):${1:T} = ${0:}
|
2013-04-13 13:45:21 -04:00
|
|
|
############################
|
|
|
|
# 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
|
2013-11-16 14:45:48 -05:00
|
|
|
Array${1:[T]}${0:()}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet buf
|
2013-11-16 14:45:48 -05:00
|
|
|
Buffer${1:[T]}${0:()}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet list
|
2013-11-16 14:45:48 -05:00
|
|
|
List${1:[T]}${0:()}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet tpl
|
2013-11-16 14:45:48 -05:00
|
|
|
Tuple${1:2}[${2:T},${0:T}]
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet set
|
2013-11-16 14:45:48 -05:00
|
|
|
Set${1:[T]}${0:()}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet hset
|
2013-11-16 14:45:48 -05:00
|
|
|
HashSet${1:[T]}${0:()}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet mhset
|
2013-11-16 14:45:48 -05:00
|
|
|
mutable.HashSet${1:[T]}${0:()}
|
2013-04-13 13:45:21 -04:00
|
|
|
#for maps
|
|
|
|
snippet keyval
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:key}->${2:val}${0:, keyval}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet map
|
2013-11-16 14:45:48 -05:00
|
|
|
Map[${1:T},${2:T}]${0:(keyval)}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet hmap
|
2013-11-16 14:45:48 -05:00
|
|
|
HashMap[${1:T},${2:T}]${0:(keyval)}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet mmap
|
2013-11-16 14:45:48 -05:00
|
|
|
mutable.Map[${1:T},${2:T}]${0:(keyval)}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet mhmap
|
2013-11-16 14:45:48 -05:00
|
|
|
mutable.HashMap[${1:T},${2:T}]${0:(keyval)}
|
2013-04-13 13:45:21 -04:00
|
|
|
#TODO add TreeMap and TreeSet
|
|
|
|
#asInstanceOf[]
|
|
|
|
snippet as
|
|
|
|
${1:name}.asInstanceOf[${2:T}]
|
|
|
|
#isInstanceOf[]
|
2014-04-18 08:58:02 -04:00
|
|
|
snippet is
|
2013-04-13 13:45:21 -04:00
|
|
|
${1:name}.isInstanceOf[${2:T}]
|
2014-04-18 08:58:02 -04:00
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
#collections methods
|
|
|
|
|
|
|
|
#scope() with one arg
|
|
|
|
snippet (a
|
2013-11-16 14:45:48 -05:00
|
|
|
(${1:a} => ${0})
|
2013-04-13 13:45:21 -04:00
|
|
|
#scope() with two args
|
|
|
|
snippet {(
|
|
|
|
{(${1:a},${2:b}) =>
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#filter
|
|
|
|
snippet filter
|
2013-11-16 14:45:48 -05:00
|
|
|
${0:name}.filter (a
|
2013-04-13 13:45:21 -04:00
|
|
|
#map function
|
|
|
|
snippet mapf
|
2013-11-16 14:45:48 -05:00
|
|
|
${0:name}.map (a
|
2013-04-13 13:45:21 -04:00
|
|
|
#flatmap
|
|
|
|
snippet flatmap
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:name}.flatMap${0:[T]}(a
|
2013-04-13 13:45:21 -04:00
|
|
|
#fold left
|
|
|
|
snippet fldl
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:name}.foldLeft(${0:first}) {(
|
2013-04-13 13:45:21 -04:00
|
|
|
#fold right
|
|
|
|
snippet fldr
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:name}.foldRight(${0:first}) {(
|
2013-04-13 13:45:21 -04:00
|
|
|
#fold left operator(if u wanna reduce readability of ur code)
|
|
|
|
#use wildcard symbols
|
|
|
|
snippet /:
|
2013-11-16 14:45:48 -05:00
|
|
|
(${1:first}/:${2:name})(${0})
|
2013-04-13 13:45:21 -04:00
|
|
|
#fold right operator
|
|
|
|
snippet :\
|
2013-11-16 14:45:48 -05:00
|
|
|
(${1:first}:\${2:name})(${0})
|
2013-04-13 13:45:21 -04:00
|
|
|
#reduce left
|
|
|
|
snippet redl
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:name}.reduceLeft[${0:T}] {(
|
2013-04-13 13:45:21 -04:00
|
|
|
#reduce right
|
|
|
|
snippet redr
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:name}.reduceRight[${0:T}] {(
|
2013-04-13 13:45:21 -04:00
|
|
|
#zipWithIndex(safe way).
|
|
|
|
#see http://daily-scala.blogspot.com/2010/05/zipwithindex.html
|
|
|
|
snippet zipwi
|
2013-11-16 14:45:48 -05:00
|
|
|
${0:name}.view.zipWithIndex
|
2013-04-13 13:45:21 -04:00
|
|
|
#split
|
|
|
|
snippet spl
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:name}.split("${0:,}")
|
2013-04-13 13:45:21 -04:00
|
|
|
#end
|
|
|
|
snippet val
|
2013-11-16 14:45:48 -05:00
|
|
|
val ${1:name}${2:: T} = ${0:value}
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet var
|
2013-11-16 14:45:48 -05:00
|
|
|
var ${1:name}${2:: T} = ${0:value}
|
2013-04-13 13:45:21 -04:00
|
|
|
############################
|
|
|
|
# classes
|
|
|
|
#
|
|
|
|
#extends
|
|
|
|
snippet extends
|
2013-11-16 14:45:48 -05:00
|
|
|
extends ${0:what}
|
2013-04-13 13:45:21 -04:00
|
|
|
#with
|
|
|
|
snippet with
|
2013-11-16 14:45:48 -05:00
|
|
|
with ${1:what}${0: with}
|
2013-04-13 13:45:21 -04:00
|
|
|
#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"}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#class
|
|
|
|
snippet class
|
|
|
|
class ${1:name}${2:(arg)}${3: extends }${4: with} {
|
|
|
|
${5:override def toString = "$1"}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#object
|
|
|
|
snippet object
|
2013-11-16 14:45:48 -05:00
|
|
|
object ${1:name}${2:(arg)}${3: extends }${4: with} ${0:}
|
2013-04-13 13:45:21 -04:00
|
|
|
#trait
|
|
|
|
snippet trait
|
|
|
|
trait ${1:name}${2: extends }${3: with} {
|
2013-11-16 14:45:48 -05:00
|
|
|
${0:}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#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}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
#case class
|
|
|
|
snippet casecl
|
2013-11-16 14:45:48 -05:00
|
|
|
case class ${1:name}${2:(arg)}${3: extends }${4: with} ${0:}
|
2013-04-13 13:45:21 -04:00
|
|
|
############################
|
|
|
|
# testing
|
|
|
|
#
|
|
|
|
#scalatest imports
|
|
|
|
snippet scalatest
|
|
|
|
${1:import org.scalatest.Suite}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0:import org.scalatest.FunSuite}
|
2013-04-13 13:45:21 -04:00
|
|
|
#assert
|
|
|
|
snippet assert
|
2015-01-18 07:58:28 -05:00
|
|
|
assert(${1:a} === ${0:b})
|
2013-04-13 13:45:21 -04:00
|
|
|
#ensuring(p 296)
|
|
|
|
snippet ensuring
|
2013-11-16 14:45:48 -05:00
|
|
|
ifel ensuring(${1:a}==${0:b})
|
2013-04-13 13:45:21 -04:00
|
|
|
#expect
|
|
|
|
snippet expect
|
2015-01-18 07:58:28 -05:00
|
|
|
expect(${1:what}) {
|
|
|
|
${0}
|
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
#intercept
|
|
|
|
snippet intercept
|
2015-01-18 07:58:28 -05:00
|
|
|
intercept[${1:IllegalArgumentException}] {
|
|
|
|
${0}
|
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
#test
|
|
|
|
snippet test
|
2015-01-18 07:58:28 -05:00
|
|
|
test("${1:description}") {
|
|
|
|
${0}
|
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
#suite
|
|
|
|
snippet suite
|
2013-11-16 14:45:48 -05:00
|
|
|
class ${0:name} extends Suite {
|
2013-04-13 13:45:21 -04:00
|
|
|
def test() {
|
|
|
|
}
|
|
|
|
#funsuite
|
|
|
|
snippet fsuite
|
|
|
|
class ${1:name} extends FunSuite {
|
2013-11-16 14:45:48 -05:00
|
|
|
test("${0:description}") {
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
############################
|
|
|
|
# SBT
|
|
|
|
#
|
|
|
|
snippet webproject
|
|
|
|
import sbt._
|
|
|
|
|
|
|
|
class ${1:Name}(info: ProjectInfo) extends DefaultWebProject(info) {
|
2013-11-16 14:45:48 -05:00
|
|
|
val liftVersion = "${0:2.3}"
|
2013-04-13 13:45:21 -04:00
|
|
|
|
|
|
|
override def libraryDependencies = Set(
|
|
|
|
|
|
|
|
) ++ super.libraryDependencies
|
|
|
|
|
|
|
|
val snapshots = ScalaToolsSnapshots
|
|
|
|
}
|
|
|
|
#depencies
|
|
|
|
snippet liftjar
|
2013-11-16 14:45:48 -05:00
|
|
|
"net.liftweb" %% "${0:lib}" % liftVersion % "compile->default",
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet jettyjar
|
2013-11-16 14:45:48 -05:00
|
|
|
"org.mortbay.jetty" % "jetty" % "${0:version}" % "test->default",
|
2013-04-13 13:45:21 -04:00
|
|
|
############################
|
|
|
|
# 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
|