Skip to content

Instantly share code, notes, and snippets.

@thurt
Created April 7, 2016 20:17
Show Gist options
  • Save thurt/ce42a5e0d91a97df1e0c32710f0acd9c to your computer and use it in GitHub Desktop.
Save thurt/ce42a5e0d91a97df1e0c32710f0acd9c to your computer and use it in GitHub Desktop.
filter a stream of objects by their key property
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