Created
April 10, 2020 01:47
-
-
Save joebutler2/7034e18ecdc17764fd9da1bcc58e43ac to your computer and use it in GitHub Desktop.
How to implement the complement function from Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TIL in Clojure the complement function takes a predicate and | |
# returns a function that is like the original function but negates | |
# the results. | |
# E.g. | |
# def is_greater(a, b); a > b; end | |
# complement(:is_greater)[1, 2] # => true | |
def complement(method_name) | |
lambda do |*args| | |
!method(method_name).call(*args) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment