Skip to content

Instantly share code, notes, and snippets.

@cacheflow
Created August 26, 2019 22:35
Show Gist options
  • Save cacheflow/c20aeeae7137221b0df01da1358127e3 to your computer and use it in GitHub Desktop.
Save cacheflow/c20aeeae7137221b0df01da1358127e3 to your computer and use it in GitHub Desktop.
import isNil from "@unction/isnil";
export default function get(name: any) {
return function getProperty(keyedFunctor: any): null | unknown {
if (isNil(keyedFunctor)) {
return keyedFunctor;
}
if (keyedFunctor.get) {
return keyedFunctor.get(name);
}
return keyedFunctor[name];
};
}
get('hello')(new Map([['hello', 'world']]))
get('hello')({ hello: 'world' })
get('hello')({ goodbye: 'world' })
get(0)(['hello world'])
get(0)('hello world')
get(0)(null)
get(0)(undefined)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment