Created
December 7, 2013 15:31
-
-
Save christiantakle/7843962 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Ideas | |
//-- note (() -> IO), random function | |
//-- Maybe denote it with a lambda instead | |
//+ given :: (a -> Bool) -> (() -> IO) -> Maybe IO | |
//+ ifthen :: (a -> Bool) -> (() -> IO) -> Maybe IO | |
function ifthen(predicate, action) { | |
if (predicate()) { | |
action(); | |
} | |
} | |
//-- Alias ------------------------------------------------------------ | |
//+ given :: (a -> Bool) -> (() -> IO) -> Maybe IO | |
var given = ifthen; | |
//+ when :: (a -> Bool) -> (() -> IO) -> Maybe IO | |
var when = ifthen; | |
//+ ifelse :: (a -> Bool) -> (() -> IO) -> (() -> IO) -> Maybe IO | |
function ifelse(predicate, if_action, else_action) { | |
if (predicate()) { | |
if_action(); | |
} else { | |
else_action(); | |
} | |
} | |
//-- Examples --------------------------------------------------------- | |
ifthen(isLoggedIn, welcome); | |
given(isLoggedIn, welcome); | |
when(loggedIn, welcome); | |
//-- Make it polymorphic? With optional else path | |
given(isLoggedIn, welcome, signup); | |
ifelse(isLoggedIn, welcome, signup); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment