Skip to content

Instantly share code, notes, and snippets.

@Killavus
Created September 20, 2015 20:49
Show Gist options
  • Save Killavus/dd2be6445f83b32cc345 to your computer and use it in GitHub Desktop.
Save Killavus/dd2be6445f83b32cc345 to your computer and use it in GitHub Desktop.
Processing graph-data. Each of node has a type. I leverage this knowledge to not 'ask', but tell what I want to do.
function emptyFn() {}
function matchNode(node, typeFunctions) {
return (typeFunctions[node.type] || emptyFn)(node);
}
// Example usage:
neighbourList.forEach(function(node) {
result = result.concat(
matchNode(node, {
Type1: continuationForType1,
Type2: continuationForType2...
})
)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment