Monday 15 June 2015

.net - PowerShell: an elegant way to create closures -


told me that I have to call the method to create closer from block.

Is there a great way to make closures from blocks? (E.g. a wrapping function, surname?, ...)

Example:

  {block} $ {close} #  

You can create a function that takes a script block, calls GetNewClosure and returns the closure. It is important that you call this function like dot operator:

  function => ($ Scriptblock) $ _ sb_) {$ _sb_.GetNewClosure ()} function A ($ block) {b (. = & Gt; {host-host 2; & amp; $ block})} function B ($ block) {Write-host1; And $ block} A {Write-host 3}  

Not sure that it is much better to call GetNewClosure () on the script block yet. Note that you can choose some other names for the function. I was going to some things like C # Lambdas.


No comments:

Post a Comment