File: prism-moonscript.html

package info (click to toggle)
node-prismjs 1.30.0%2Bdfsg%2B~1.26.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,220 kB
  • sloc: javascript: 27,628; makefile: 9; sh: 7; awk: 4
file content (64 lines) | stat: -rw-r--r-- 1,367 bytes parent folder | download | duplicates (3)
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
<h2>Full example</h2>
<pre><code>class List
  new: (t) =>
    if t then return t

  append: table.insert
  join: table.concat

  map: (f,...) => List [f x,... for x in *self]

  -- apply a function on a list in-place
  apply: (f,...) =>
    for i = 1,#@ do @[i] = f @[i],...
    self

  clone: => @slice 1

  slice: (i1,i2=#@) =>
    -- workaround for MS slice bug
    if i2 &lt; 0 then i2 = #@ + i2 + 1
    List [x for x in *self[i1,i2]]

  extend: (other) =>
    i = #self + 1
    for o in *other
        self[i] = o
        i += 1
    self

  partition: (pred,...) =>
    res = {}
    for x in *@
        k = pred x,...
        if not res[k] then res[k] = List!
        res[k]\append x
    res

  lpartition: (n,npred,...) =>
      res = List[List{} for i = 1,n]
      for x in *@
        k = npred x,...
        if k >= 1 and k &lt;= n
            res[k]\append x
      res

  __concat: (l1,l2) ->
        List.clone(l1)\extend l2

  __tostring: =>
    tmp = @slice(1,10)\apply tostring
    if #@ > 10 then tmp\append '...'
    "["..tmp\join(',').."]"

-- hack to modify class so its constructor may return a new self
patch = (klass) -> getmetatable(klass).__call = (cls,...) ->
    self = setmetatable {}, cls.__base
    newself = cls.__init self, ...
    if newself
        self = setmetatable newself, cls.__base
    self

patch List

return List</code></pre>