Skip to content

Instantly share code, notes, and snippets.

@rklancer
Created September 23, 2011 17:12
Show Gist options
  • Save rklancer/1237915 to your computer and use it in GitHub Desktop.
Save rklancer/1237915 to your computer and use it in GitHub Desktop.
do =>
toMatchUsing = (matcher) ->
(pairs) ->
return false if @actual?.length isnt pairs.length or typeof @actual isnt 'object'
return false for a, i in @actual when not matcher( a, pairs[i] )
true
@addMatchers(
toEqualPairs: toMatchUsing (a, [x, y]) -> a[0] is x and a[1] is y
toEqualPointsDefinedBy: toMatchUsing (a, [x, y]) -> a.get('x') is x and a.get('y') is y
)
@rklancer
Copy link
Author

Thanks to TheJH on Freenode #coffeescript for the style advice!

@rklancer
Copy link
Author

And matyr for the pointer to the ?. operator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment