Code coverage report for nodash/lib/Maybe.js

Statements: 100% (17 / 17)      Branches: 100% (14 / 14)      Functions: 100% (7 / 7)      Lines: 100% (17 / 17)      Ignored: none     

All files » nodash/lib/ » Maybe.js
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54      1     1 41     5     3 1   2           9       7 5   2       4 3   1       5 2   3                    
/* vim: set et sw=2 ts=2: */
'use strict';
 
module.exports = [ 'idf', 'is', 'compose', 'compose2', 'filter', 'map', 'List', 'singleton', 'emptyList',
  function (idf, is, compose, compose2, filter, map, List, singleton, emptyList) {
 
  function isJust(thing) {
    return thing !== null && thing !== undefined;
  }
 
  return {
 
    maybe: function (def, fun, value) {
      if (value === null || value === undefined) {
        return def;
      }
      return fun(value);
    },
 
    isJust: isJust,
 
    isNothing: function (thing) {
      return !isJust(thing);
    },
 
    fromMaybe: function (def, maybe) {
      if (isJust(maybe)) {
        return maybe;
      }
      return def;
    },
 
    listToMaybe: function (xs) {
      if (is(List, xs)) {
        return xs.isEmpty() ? null : xs.head();
      }
      throw new TypeError();
    },
 
    maybeToList: function (thing) {
      if (isJust(thing)) {
        return singleton(thing);
      }
      return emptyList();
    },
 
    catMaybes: filter(isJust),
 
    mapMaybe: compose2(filter(isJust), map)
      
  };
  
}];