Skip to content

Instantly share code, notes, and snippets.

@wgross
Last active October 30, 2018 09:37
Show Gist options
  • Save wgross/9dda5bf30cee9d9159caa8e396e88482 to your computer and use it in GitHub Desktop.
Save wgross/9dda5bf30cee9d9159caa8e396e88482 to your computer and use it in GitHub Desktop.
POC for powershell delegateish scriptblock with context. Possible use as some kind of builder pattern
class Context {
$Data
}
filter require_context {
if( $_ -is [Context]) {
$_
} else {
throw "missing context"
}
}
function parent {
param([scriptblock]$children)
$children.InvokeReturnAsIs([Context]@{Data ="data"})|Write-Output
}
parent {
[Context]$c = $args[0]|require_context
$c.Data+"child1"
$c.Data+"child2"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment