<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>PowerShell LINQ: Skip-While</title><link>http://blogs.msdn.com/jaredpar/archive/2009/01/14/powershell-linq-skip-while.aspx</link><description>Next up in the PowerShell LINQ series is SkipWhile .&amp;#160; This LINQ function takes an enumerable instance and a predicate.&amp;#160; The function will skip the elements in the enumerable while the predicate is true.&amp;#160; The argument to the predicate is</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Dew Drop &amp;ndash; January 29, 2009 | Alvin Ashcraft's Morning Dew</title><link>http://blogs.msdn.com/jaredpar/archive/2009/01/14/powershell-linq-skip-while.aspx#9383334</link><pubDate>Thu, 29 Jan 2009 19:32:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9383334</guid><dc:creator>Dew Drop &amp;ndash; January 29, 2009 | Alvin Ashcraft's Morning Dew</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.alvinashcraft.com/2009/01/29/dew-drop-january-29-2009/"&gt;http://www.alvinashcraft.com/2009/01/29/dew-drop-january-29-2009/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: PowerShell LINQ: Skip-While</title><link>http://blogs.msdn.com/jaredpar/archive/2009/01/14/powershell-linq-skip-while.aspx#9429966</link><pubDate>Wed, 18 Feb 2009 08:31:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9429966</guid><dc:creator>Josh Einstein</dc:creator><description>&lt;p&gt;Here's a trick to get your lambdas to use the standard $_ convention for current item. &lt;/p&gt;
&lt;p&gt;This used to work and I think it still does if the function is a &amp;quot;normal&amp;quot; .ps1 style function:&lt;/p&gt;
&lt;p&gt;function Blah([ScriptBlock]$Predicate) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; process { if (&amp;amp;$Predicate) { $_ } }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;1,2,3 | blah { $_ -eq 3 }&lt;/p&gt;
&lt;p&gt;But that no longer works in PowerShell 2.0 CTP 3 when using a .psm1. I still can't quite figure out why but I think it has something to do with the way PowerShell is capturing the variable before calling the function.&lt;/p&gt;
&lt;p&gt;So anyway, this does in fact work:&lt;/p&gt;
&lt;p&gt;function Blah([ScriptBlock]$Predicate) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; process { if (Invoke-Expression &amp;quot;$Predicate&amp;quot;) { $_ } }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Notice how the Predicate is being converted back to a string and passed to iex which inherits the $_ variable.&lt;/p&gt;
&lt;p&gt;Anyhow, I got sick of using $args[0] for my predicates when everywhere else used $_ so I banged my head against the wall for hours until I figured out a suitable workaround.&lt;/p&gt;
</description></item></channel></rss>