2 Vector
:= Sequence
clone setItemType("float32") setEncoding("number")
3 vector
:= method(v
:= Vector
clone; call evalArgs
foreach(n
, v
append(n
)); v
)
6 ImmutableSequence
:= ""
7 String := ImmutableSequence
11 setSlot("..", method(arg
, self asString
cloneAppendSeq(arg asString
)))
13 docSlot("repeated(n)", "Returns a new sequence containing the receiver repeated n number of times.")
16 n
repeat(s
appendSeq(self))
20 docSlot("alignLeftInPlace(width, [padding])", "Same as align left but operation is performed on the receiver.")
21 alignLeftInPlace
:= method(width
, padding
,
23 if(padding
isNil or padding size
== 0,
26 ((width
- size
) / padding size
) ceil
repeat(appendSeq(padding
))
27 setSize(width
max(originalSize
))
30 docSlot("alignLeft(width, [padding])", """
33 Io> "abc" alignLeft(10, "-")
35 Io> "abc" alignLeft(10, "-=")
39 alignLeft
:= method(width
, padding
, asMutable
alignLeftInPlace(width
, padding
))
41 docSlot("alignRight(width, [padding])", """
44 Io> "abc" alignRight(10, "-")
46 Io> "abc" alignRight(10, "-=")
50 alignRight
:= method(width
, padding
,
51 Sequence
clone alignLeftInPlace(width
- size
, padding
) appendSeq(self)
54 docSlot("alignCenter(width, [padding])", """
57 Io> "abc" alignCenter(10, "-")
59 Io> "abc" alignCenter(10, "-=")
63 alignCenter
:= method(width
, padding
,
64 alignRight(((size
+ width
) / 2) floor
, padding
) alignLeftInPlace(width
, padding
)
67 asSimpleString
:= method("\"" .. self asString
.. "\"")
69 docSlot("split(optionalArg1, optionalArg2, ...)", """
70 Returns a list containing the non-empty sub-sequences of the receiver divided by the given arguments.
71 If no arguments are given the sequence is split on white space.
74 "a b c d" splitNoEmpties => list("a", "b", "c", "d")
75 "a***b**c*d" splitNoEmpties("*") => list("a", "b", "c", "d")
76 "a***b||c,d" splitNoEmpties("*", "|", ",") => list("a", "b", "c", "d")
80 splitNoEmpties
:= method(
81 self performWithArgList("split", call evalArgs
) selectInPlace(size
!= 0)
84 docSlot("findNthSeq(aSequence, n)", "Returns a number with the nth occurence of aSequence")
85 findNthSeq
:= method(str
, n
,
86 num
:= self findSeq(str
)
87 if(num
isNil, return nil
)
88 if(n
== 1, return num
)
89 num
+ self slice(num
+ 1, self size
) findNthSeq(str
, n
- 1)
93 orderedSplit
:= method(
94 separators
:= call evalArgs
95 if(separators size
== 0, return list(self))
99 separators
foreach(separator
,
100 j
:= findSeq(separator
, i
) ifNil(
104 r
append(slice(i
, j
))
106 skipped
repeat(r
append(nil
))
109 i
= j
+ separator size
116 skipped
repeat(r
append(nil
))
120 docSlot("prependSeq(object1, object2, ...)", "Prepends given objects asString in reverse order to the receiver. Returns self.")
121 prependSeq
:= method(self atInsertSeq(0, call evalArgs join
); self)
123 sequenceSets
:= Map clone do(
124 atPut("lowercaseSequence",
126 "abcdefghijklmnopqrstuvwxyz" foreach(v
, lst
append(v
))
129 atPut("uppercaseSequence",
131 at("lowercaseSequence") foreach(v
, lst
append(v asUppercase
))
134 atPut("digitSequence",
136 "0123456789" foreach(v
, lst
append(v
))
143 docSlot("asHex", "Returns a hex string for the receiving sequence, e.g., \"abc\" asHex -> \"616263\".")
146 self foreach(c
, r
appendSeq(c asHex
alignRight(2, "00")))