Skip to content

Instantly share code, notes, and snippets.

@leontastic
Last active January 3, 2016 17:49
Show Gist options
  • Save leontastic/8498250 to your computer and use it in GitHub Desktop.
Save leontastic/8498250 to your computer and use it in GitHub Desktop.
Clone of Racket assoc built-in function, except uses equal? instead of is-equal?, and returns an error instead of #f if the element does not exist. See here: http://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._assoc%29%29
; find-assoc: Any AL -> (listof Any)
; (find-assoc id al) produces the first element of al whose *car* is equal to id.
(define (find-assoc id al)
(first (filter (lambda (x) (equal? (first x) id)) al)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment