Last active
June 2, 2020 18:23
-
-
Save kane-thornwyrd/88b7fe3c5faccb415fe02b9a5561c4d1 to your computer and use it in GitHub Desktop.
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
const targets = [ | |
{}, | |
{}, | |
{id:2}, | |
{id:42}, | |
{id:1}, | |
{id:0}, | |
] | |
const targetId = 42 | |
const idSelector = | |
collection => | |
id => | |
collection.length <= 0 ? | |
null : | |
collection.find(entry => entry.id == id) | |
const targetSelector = idSelector(targets) | |
const target = targetSelector(targetId) | |
// Or even: | |
// const target = idSelector(targets)(targetId) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment