moxie.json raw
1 {
2 "Named return function": {
3 "prefix": "fn",
4 "body": [
5 "func ${1:Name}(${2:args}) (${3:result} ${4:Type}) {",
6 "\t$0",
7 "\treturn",
8 "}"
9 ],
10 "description": "A Moxie function must name every return value."
11 },
12 "Pointer receiver method": {
13 "prefix": "meth",
14 "body": [
15 "func (${1:r} *${2:Type}) ${3:Name}(${4:args}) (${5:result} ${6:Type}) {",
16 "\t$0",
17 "\treturn",
18 "}"
19 ],
20 "description": "Only method receivers may be written to, and only a pointer receiver is allowed in user code."
21 },
22 "Sovereign self-mutating type": {
23 "prefix": "sovereign",
24 "body": [
25 "type ${1:Thing} struct {",
26 "\t${2:field} ${3:Type}",
27 "}",
28 "",
29 "func (${4:t} *${1:Thing}) ${5:Add}(${6:v} ${3:Type}) {",
30 "\t${4:t}.${2:field} = ${6:v}",
31 "}"
32 ],
33 "description": "A named struct with a method that stores into a receiver field owns a sovereign arena."
34 },
35 "init and zero-value globals": {
36 "prefix": "init",
37 "body": [
38 "var ${1:table} ${2:*Table}",
39 "",
40 "func init() {",
41 "\t${1:table} = new${2:Table}()",
42 "}"
43 ],
44 "description": "A program's main package cannot declare init; other packages use init() plus zero-value globals."
45 },
46 "Slice with length and capacity": {
47 "prefix": "slice",
48 "body": ["${1:b} := []${2:byte}{:${3:n}:${4:cap}}"],
49 "description": "Presize exactly and write through a cursor. There is no make()."
50 },
51 "Ensure before a spread push": {
52 "prefix": "ensure",
53 "body": ["${1:b} = mxutil.Ensure(${1:b}, len(${2:src}))", "push(${1:b}, ${2:src}...)"],
54 "description": "push does not grow; a spread needs Ensure(len(src)) first."
55 },
56 "Spawn a worker": {
57 "prefix": "spawn",
58 "body": [
59 "in := chan ${1:Request}{}",
60 "out := chan ${2:Response}{}",
61 "done := spawn(${3:Worker}, in, out)",
62 "\t$0",
63 "<-done"
64 ],
65 "description": "Channels are fixed at spawn time; a worker serves its inbox and is never spawned per job."
66 },
67 "Interface implementation assertion": {
68 "prefix": "iface",
69 "body": [
70 "if ${1:v}, ok := ${2:x}.(${3:fmt.Stringer}); ok {",
71 "\t$0",
72 "}"
73 ],
74 "description": "There is no reflect and no empty interface; assert to a named interface."
75 },
76 "Error return": {
77 "prefix": "err",
78 "body": ["return ${1:zero}, errors.New(\"${2:message}\")"],
79 "description": "Named returns plus errors.New from the errors package."
80 },
81 "Switch without a tag": {
82 "prefix": "switch",
83 "body": ["switch {", "case ${1:cond}:", "\t$0", "default:", "}"]
84 },
85 "Kind-switch on an enum": {
86 "prefix": "kinds",
87 "body": [
88 "switch ${1:k} {",
89 "case ${2:KindOne}:",
90 "\t$0",
91 "default:",
92 "}"
93 ]
94 }
95 }
96