aboutsummaryrefslogtreecommitdiff
path: root/lib/results.js
blob: 5bd81c0699c3140c9f2f0d1d28692ec6cdad169e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
exports.Result = Result;
exports.warning = warning;


function Result(value, messages) {
    this.value = value;
    this.messages = messages || [];
}

Result.prototype.map = function(func) {
    return new Result(func(this.value), this.messages);
};

Result.prototype.mapThen = function(func) {
    var messages = this.messages;
    return func(this.value).then(function(resultValue) {
        return new Result(resultValue, messages);
    });
};

function warning(message) {
    return {
        type: "warning",
        message: message
    };
}