Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
92 lines (76 sloc) 1.67 KB
max = `a, b | (a > b) ? a ! b`
min = `a, b | (a < b) ? a ! b`
@NSPointerArray {
- fold: lambda {
i = 0
accum = lambda(self[i++])
accum = lambda(self[i++], accum) until i >= self size
^accum
}
- map: lambda {
^self fold: `elem, result=[] | result push: lambda(elem)`
}
- appendArray: anotherArray {
result = self copy
anotherArray each: { elem |
result push: elem
}
^result
}
- concat {
^self fold: { elem, accum=[] |
^elem fold: `subElem, newAccum=accum | newAccum push: subElem`
}
}
- max {
^self fold: max
}
- min {
^self fold: min
}
- reverse {
result = []
i = self size
result push: self[i] until --i == 0
^result
}
- filter:lambda {
result = []
self each: { elem |
result push: elem if lambda(elem)
}
^result
}
- any:lambda {
i = 0
until i >= self size {
^self[i] if lambda(self[i])
}
}
- partition:lambda {
a = []
b = []
self each: { elem |
if lambda(elem) then a push:elem
else b push:elem
}
^[a,b]
}
- zip:otherArray {
length = max(self size, otherArray size)
result = []
i = -1
until ++i >= length {
result push: self[i]
result push: otherArray[i]
}
^result
}
}
a = [1,2,3] zip: [4,5,6]
a print
a = [[1,2,3], [4,5,6]] concat
a print
foo = [1,2,3,4,5,6,7,8,9] partition:`obj | obj < 5`
foo print
max(1,2) print