Created
April 7, 2016 20:17
-
-
Save thurt/ce42a5e0d91a97df1e0c32710f0acd9c to your computer and use it in GitHub Desktop.
filter a stream of objects by their key property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Stream = require('stream.js') // https://github.com/dionyziz/stream.js | |
var myStream = Stream.make({ | |
key:'please' | |
}, { | |
key: 'filter' | |
}, { | |
key: 'this' | |
}, { | |
key: 'data' | |
}) | |
var FilterByKey = S => contains_str => S.filter(item => ~item.key.indexOf(contains_str)) | |
var myFilter = FilterByKey(myStream) | |
myFilter('a').print() | |
/* | |
{ key: 'please' } | |
{ key: 'data' } | |
*/ | |
myFilter('i').print() | |
/* | |
{ key: 'filter' } | |
{ key: 'this' } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment