Created
February 10, 2020 01:29
-
-
Save joepie91/67acc5ab3af5f86697819d4db2627b7e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const immutableCollection = require("./"); | |
let items = [{ | |
id: 1, | |
color: "blue" | |
}, { | |
id: 2, | |
color: "red" | |
}, { | |
id: 3, | |
color: "red" | |
}, { | |
id: 4, | |
color: "red" | |
}, { | |
id: 5, | |
color: "blue" | |
}, { | |
id: 6, | |
color: "blue" | |
}, { | |
id: 7, | |
color: "red" | |
}]; | |
let collection = immutableCollection(items); | |
let modified = collection.modify((collection) => { | |
return collection | |
.subset((blueItems) => { | |
return blueItems | |
.select((item) => item.color === "blue") | |
.remove(); | |
}) | |
.subset((oddItems) => { | |
return oddItems | |
.select((item) => item.id % 2 === 1) | |
.map((item) => ({ ... item, color: "green" })); | |
}) | |
.map((item) => ({ ... item, id: item.id * 2 })); | |
}); | |
console.log(modified); |
This file contains hidden or 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
[ { id: 4, color: 'red' }, | |
{ id: 6, color: 'green' }, | |
{ id: 8, color: 'red' }, | |
{ id: 14, color: 'green' } ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment