Skip to content

Instantly share code, notes, and snippets.

@kane-thornwyrd
Last active June 2, 2020 18:23
Show Gist options
  • Save kane-thornwyrd/88b7fe3c5faccb415fe02b9a5561c4d1 to your computer and use it in GitHub Desktop.
Save kane-thornwyrd/88b7fe3c5faccb415fe02b9a5561c4d1 to your computer and use it in GitHub Desktop.
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