Repository: plaid/sanctuary (js)

Issue:
S.pluck?
This is really sheer laziness on my part but my code is littered with `R.map(S.get('key'), arr))`, it's an improvement on having to remember to do `R.reject(R.isNil, R.pluck('key', arr))` whenever I use `R.pluck` but it would be nice to have some sugar around such a common pattern.

Pull request description:
Add S.pluck functionality
Resolves #20 

Patch:
diff --git a/index.js b/index.js
index 5337c41..90911db 100644
--- a/index.js
+++ b/index.js
@@ -277,6 +277,20 @@
     return Nothing();
   });
 
+  //. pluck :: String -> [{String: *}] -> [Maybe *]
+  //.
+  //. Takes a list of objects and plucks the value of the specified key
+  //. for each object in the list. Returns the value wrapped in a Just
+  //. if an object has the key and a Nothing if it does not.
+  //.
+  //. ```javascript
+  //. > pluck('a', [{a: 1, b: 2}, {a: 4, b: 5}, {b: 3, c: 7}])
+  //. [Just(1), Just(4), Nothing()]
+  //. ```
+  S.pluck = R.curry(function(key, xs) {
+    return R.map(get(key), xs);
+  });
+
   //  object  ////////////////////////////////////////////////////////////////
 
   //  get :: String -> Object -> Maybe *


Test patch:
diff --git a/test/index.js b/test/index.js
index 3c6c976..3284452 100644
--- a/test/index.js
+++ b/test/index.js
@@ -835,6 +835,34 @@ describe('list', function() {
 
   });
 
+  describe('pluck', function() {
+
+    it('returns array of Justs for found keys', function() {
+      var xs = [{a: 1, b: 3}, {a: 2, b: 4}, {a: 3, b: 5}];
+      var maybeXs = [S.Just(1), S.Just(2), S.Just(3)];
+      assert.deepEqual(S.pluck('a', xs), maybeXs);
+    });
+
+    it('returns array of Nothings for keys not found', function() {
+      var xs = [{a: 1, b: 3}, {a: 2, b: 4}, {a: 3, b: 5}];
+      var maybeXs = [S.Nothing(), S.Nothing(), S.Nothing()];
+      assert.deepEqual(S.pluck('c', xs), maybeXs);
+    });
+
+    it('returns Just(undefined) for defined key with no value', function() {
+      var xs = [{a: 1, b: 3}, {a: void 0, b: 4}, {a: 3, b: 5}];
+      var maybeXs = [S.Just(1), S.Just(void 0), S.Just(3)];
+      assert.deepEqual(S.pluck('a', xs), maybeXs);
+    });
+
+    it('returns an array of Maybes for various values', function() {
+      var xs = [{a: 1}, {a: void 0}, {a: 4}, {b: 1}];
+      var maybeXs = [S.Just(1), S.Just(void 0), S.Just(4), S.Nothing()];
+      assert.deepEqual(S.pluck('a', xs), maybeXs);
+    });
+
+  });
+
 });
 
 describe('object', function() {