Skip to content

Instantly share code, notes, and snippets.

@mstksg
Last active December 22, 2015 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstksg/6525682 to your computer and use it in GitHub Desktop.
Save mstksg/6525682 to your computer and use it in GitHub Desktop.
Assertion DSL for complex conditional
import Data.Maybe (isJust)
assert :: Bool -> Maybe ()
assert True = Just ()
assert False = Nothing
checkAssertions :: Maybe () -> Bool
checkAssertions = isJust
checkMatch :: Person -> Person -> Bool
checkMatch seeker candidate = checkAssertions $ do
assert $ gender candidate == preferedGender seeker
assert $ gender seeker == preferedGender candidate
assert $ minAcceptableAge seeker <= age candidate
assert $ maxAcceptableAge seeker >= age candidate
assert $ minAcceptableAge candidate <= age seeker
assert $ maxAcceptableAge cadidate >= age seeker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment