Skip to content

Instantly share code, notes, and snippets.

@Rudxain
Last active December 8, 2022 15:15
Show Gist options
  • Save Rudxain/370f6d6e8fb7571f120c53d59c375ac5 to your computer and use it in GitHub Desktop.
Save Rudxain/370f6d6e8fb7571f120c53d59c375ac5 to your computer and use it in GitHub Desktop.
Access any value within a tree, at any depth. Ported from Clojure
'use strict'
/**
@param {unknown} struct
@param {Iterable<unknown>} keys
*/
const get_in = (struct, keys) => {
for (const k of keys)
struct =
struct instanceof Map ||
struct instanceof WeakMap
? struct.get(k)
: struct[k]
return struct
}
//LICENSE: https://unlicense.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment