1
0
Fork 0
mirror of synced 2024-12-22 15:08:57 -05:00
ultimate-vim/sources_non_forked/vim-snippets/snippets/scala.snippets

361 lines
6.2 KiB
Text
Raw Normal View History

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