Created
February 27, 2011 00:25
-
-
Save robotlolita/845773 to your computer and use it in GitHub Desktop.
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
############################################################################### | |
# Compares a list using the given function. # | |
# # | |
# This is a general comparison function, that takes a sequence as the first # | |
# argument and a function as the second. # | |
# # | |
# The sequence is iterated using `all`. For each pair of items in the # | |
# sequence the callback function is called and expected to return whether the # | |
# comparison for the given pair succeeds or fails. # | |
# # | |
# If said callback returns any falsy value, the iteration is stopped and the # | |
# comparison fails — false is returned. Otherwise, if the iteration completes # | |
# successfully, the comparison succeeds — true is returned. # | |
# # | |
# Example:: # | |
# # | |
# >>> (cmp (list 1, 2, 3, 4), ((left, right) -> left < right)) # | |
# true # | |
# # | |
# Is the equivalent of:: # | |
# # | |
# >>> 1 < 2 < 3 < 4 # | |
# true # | |
# # | |
# Or in plain JavaScript, which reproduces better (and more explicitly) what # | |
# actually happens:: # | |
# # | |
# >>> (1 < 2) && (2 < 3) && (3 < 4) # | |
# true # | |
# # | |
# :param Array seq: The sequence to test. # | |
# :param Function fn: The function to test the pairs in the sequence # | |
# # | |
# :results: ``true`` or ``false``, depending on the success of the # | |
# comparison. # | |
############################################################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment