aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/vim-snippets/snippets/scala.snippets
blob: 003081ef18ff13e50da175a25ef64b116eb79894 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
################################################################
# © 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})
		${0}
#if not
snippet ifn
	if (!${1})
		${0}
#if-else
snippet ife
	if (${1})
		${2}
	else
		${0}
#if-else-if
snippet ifelif
	if (${1})
		${2}
	else if (${3})
		${0}
snippet eif
	else if (${3})
		${0}
#while loop
snippet wh
	while (${1:obj}) {
		${0}
	}
#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}
	}
#for comprehension
snippet fory
	for {
		${1:item} <- ${2:obj}
	} yield ${0}
#exceptions
snippet try
	try {
		${1}
	} catch {
		case e: FileNotFoundException => ${2}
		case e: IOException => ${3}
	} finally {
		${0}
	}
#match
snippet match
	${1: obj} match {
		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[]
snippet is
	${1:name}.isInstanceOf[${2:T}]

#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
	assert(${1:a} === ${0:b})
#ensuring(p 296)
snippet ensuring
	ifel ensuring(${1:a}==${0:b})
#expect
snippet expect
	expect(${1:what}) {
		${0}
	}
#intercept
snippet intercept
	intercept[${1:IllegalArgumentException}] {
		${0}
	}
#test
snippet test
	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