Last active
October 30, 2018 09:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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