Skip to content

Instantly share code, notes, and snippets.

var requestPromise;
function getCurrentState() {
if (requestPromise) return requestPromise;
requestPromise = ajaxRequestReturningPromise('GET', '/state.json');
reqrequestPromise.then(function() { requestPromise = null });
return requestPromise;
}
promise1 = getCurrentState()
-- | The 'partition' function splits a list into sublists of length n.
partition :: Int -> [a] -> [[a]]
partition n xs = unfoldr step xs
where step :: [a] -> Maybe ([a], [a])
step [] = Nothing
step ys = Just (take n ys, drop n ys)
@jcoglan
jcoglan / gist:167422
Created August 13, 2009 19:56 — forked from sl4m/gist:166903
// If you return a value from the `initialize()` method, that value
// is returned when you instantiate the class using `new`.
// Here, we use this to make `singleton` a class that generates
// new classes. The singleton instance is protected by a closure.
JS.singleton = new JS.Class({
initialize: function(name, parent, methods) {
var instance = null;
return new JS.Class(name, parent, {