infinispan 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/functional.js CHANGED
@@ -2,9 +2,19 @@
2
2
 
3
3
  var _ = require('underscore');
4
4
 
5
- function existy(x) { return x != null }
5
+ /**
6
+ * Checks whether a value exists (is not null or undefined).
7
+ * @param {*} x Value to check.
8
+ * @returns {boolean} True if the value is not null or undefined.
9
+ */
10
+ function existy(x) { return x != null; }
6
11
  exports.existy = existy;
7
12
 
13
+ /**
14
+ * Concatenates multiple arrays into a single array.
15
+ * @param {...Array} arguments Arrays to concatenate.
16
+ * @returns {Array} Concatenated array.
17
+ */
8
18
  function cat() {
9
19
  var head = _.first(arguments);
10
20
  if (existy(head))
@@ -14,6 +24,12 @@
14
24
  }
15
25
  exports.cat = cat;
16
26
 
27
+ /**
28
+ * Prepends a head element to a tail collection, returning a new array.
29
+ * @param {*} head Element to prepend.
30
+ * @param {Array|Arguments} tail Collection to append after head.
31
+ * @returns {Array} New array with head followed by tail elements.
32
+ */
17
33
  function construct(head, tail) {
18
34
  return cat([head], _.toArray(tail));
19
35
  }
@@ -64,8 +80,8 @@
64
80
  };
65
81
  };
66
82
 
67
- exports.greaterThan = exports.curry2(function (lhs, rhs) { return lhs > rhs });
68
- exports.lessThan = exports.curry2(function (lhs, rhs) { return lhs < rhs });
83
+ exports.greaterThan = exports.curry2(function (lhs, rhs) { return lhs > rhs; });
84
+ exports.lessThan = exports.curry2(function (lhs, rhs) { return lhs < rhs; });
69
85
 
70
86
  exports.lift = function lift(answerFun, stateFun) {
71
87
  return function(/* args */) {
@@ -101,6 +117,12 @@
101
117
  };
102
118
  };
103
119
 
120
+ /**
121
+ * Maps a function over a collection and concatenates the results.
122
+ * @param {Function} fun Mapping function returning arrays.
123
+ * @param {Array} coll Collection to map over.
124
+ * @returns {Array} Concatenated results.
125
+ */
104
126
  function mapcat(fun, coll) {
105
127
  return cat.apply(null, _.map(coll, fun));
106
128
  }
@@ -131,8 +153,19 @@
131
153
  };
132
154
 
133
155
  exports.truthy = truthy;
134
- function truthy(x) { return (x !== false) && existy(x) }
135
-
156
+ /**
157
+ * Checks whether a value is truthy (not false, null, or undefined).
158
+ * @param {*} x Value to check.
159
+ * @returns {boolean} True if the value is truthy.
160
+ */
161
+ function truthy(x) { return (x !== false) && existy(x); }
162
+
163
+ /**
164
+ * Executes an action if the condition is truthy, otherwise returns undefined.
165
+ * @param {*} cond Condition to evaluate.
166
+ * @param {Function} action Function to invoke if condition is truthy.
167
+ * @returns {*} Result of action if condition is truthy, undefined otherwise.
168
+ */
136
169
  function doWhen(cond, action) {
137
170
  if(truthy(cond))
138
171
  return action();
@@ -183,7 +216,7 @@
183
216
  return function(obj) {
184
217
  if (type === obj)
185
218
  return action(obj);
186
- }
187
- }
219
+ };
220
+ };
188
221
 
189
222
  }.call(this));