map = (values: [any], to convert: (values[0], at?: int) {any})
value: convert values[0]
new: list value length (length values)
from 1 to (length values) do (i: int)
new[i] := convert values[i] at i
new
reduce = (values: [any], to accumulate: (target, with: values[0], at?: int) {target}, startWith target? values[0]: any)
result: target
from 0 to (length values) do (i: int)
result := accumulate result with values[i] at i
result
select = (values: [any], where include: (values[0], at?: int) {bool})
new: list values[0] size (length values)
i: 0
from 0 to (length values) do (j: int)
if (include values[j] at j) then
new[i] := values[j]
i += 1
new
# Example: compute the collective amount of time spent on a course for a lecturer.
lecturer = [1, 1, 1, 2, 2, 1, 1]
lectureTimes = [20, 56, 31, 68, 49, 53, 32]
lectureViewership = [200, 189, 163, 155, 110, 148, 194]
main = ()
collectiveTimes = map lectureTimes to (time: int, i: int)
time * lectureViewership[i]
collectiveLecturerTimes = select collectiveTimes where (time: int, i: int)
lecturer[i] == 1
collectiveLecturerTime = reduce collectiveLecturerTimes to (acc: int, time: int)
acc + time