Skip to content

Instantly share code, notes, and snippets.

@leontastic
Created January 19, 2014 09:36
Show Gist options
  • Save leontastic/8502497 to your computer and use it in GitHub Desktop.
Save leontastic/8502497 to your computer and use it in GitHub Desktop.
A clone of the *remove-duplicates* built-in function in Racket. Uses *equal?* to determine if two elements are duplicates.
; remove-duplicates-clone: (listof Any) -> (listof Any)
; (remove-duplicates-clone loa) produces loa without duplicated elements while preserving the order of elements
(define (remove-duplicates-clone loa)
(foldr (lambda (x y) (cons x (filter (lambda (z) (not (equal? x z))) y))) empty loa))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment