jackdclark/five

Control flow functions are missing

taxibutler opened this issue · 1 comments

I find this library to be very difficult to use without control flow functions. This is absolutely unacceptable and should be remedied ASAP!!!

Below are a few examples how these would work:

five.times(function(){});
Executes the function passed as parameter five times.

five.moreTimes(function(){});
In case you need the function to be executed five more times, duh!

five.equals(some_variable_that_isnt_five).then(function(){}).else(function(){});
This is pretty self explanatory, I don't even know how you haven't thought about it yet!

five.times = function times(func) {
    var smallFive = five() / five();
    while(smallFive !== five()) {
        func();
        smallFive++;
    }
}

five.moreTimes = function moreTimes(func) {
    five.times(func);
    five.times(func);
}

five.equals = function equals(possibleFive) {
    var fiveObject = {}; // sorry it's not a five
    
    fiveObject[five()] = five(); // here's my apology
    
    var isFive = possibleFive == five();
    
    var functor = function(failOrSucceed) {
        return function (todo) {
            if(failOrSucceed == isFive) {
                todo();
            }
            return fiveObject;
        }
    }
    
    fiveObject["then"] = functor(true);
    fiveObject["else"] = functor(false);
    
    return fiveObject;
}