Skip to content

Instantly share code, notes, and snippets.

@drautb
Last active December 30, 2015 04:09
Show Gist options
  • Save drautb/7773632 to your computer and use it in GitHub Desktop.
Save drautb/7773632 to your computer and use it in GitHub Desktop.
A curried version of Racket's map function.
#lang plai
(define nums '(0 1 2 3 4))
(test (map add1 nums) '(1 2 3 4 5))
(define (my-map f l)
(cond
[(empty? l) l]
[else (cons (f (first l))
(my-map f (rest l)))]))
(test (my-map add1 nums) '(1 2 3 4 5))
(define (my-curried-map f)
(λ (l)
(cond
[(empty? l) l]
[else (cons (f (first l))
((my-curried-map f) (rest l)))])))
(test ((my-curried-map add1) nums) '(1 2 3 4 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment