Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The recursive function used by MAP
- var make_map =
- next_map =>
- new_list =>
- fn =>
- list =>
- (list_acc =>
- // Have we reached the end of the list?
- (IS_LAST(list)
- // Yup, so reverse the items in list_acc and
- // we're done
- (REVERSE(list_acc))
- // Nope, so recursively call ourselves passing
- // in the list accumulator, the function being
- // applied and whatever is left in the current
- // list
- (f => (next_map(list_acc)
- (fn)
- (TAIL(list)))
- (f))))
- // Pass the first list item to the function and append the
- // modified value to the start of the new list. The
- // resulting list becomes the value of the
- // list_acc(umulator) parameter seen above
- (PAIR(fn(HEAD(list)))(new_list));
- // Create the MAP function using the Y-Combinator and an initial
- // empty list
- var MAP = Y(make_map)(EMPTY);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement