<?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>DIY: Ternary operator</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx</link><description>&amp;lt;Changed DYI =&amp;gt; DIY. jps&amp;gt; At Microsoft, "to ship is to choose". One of the things we were very disappointed in not being able to ship in V1.0 is a ternary operator . Here is a description of a ternary operator from Wikipedia: Many programming</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>leedesmond&amp;#8217;s blog  &amp;raquo; Blog Archive   &amp;raquo; Ternary operator ?:</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx#1386372</link><pubDate>Sun, 31 Dec 2006 00:44:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1386372</guid><dc:creator>leedesmond’s blog  » Blog Archive   » Ternary operator ?:</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.leedesmond.com/weblog/?p=50"&gt;http://www.leedesmond.com/weblog/?p=50&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: DYI: Ternary operator</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx#1387022</link><pubDate>Sun, 31 Dec 2006 03:39:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1387022</guid><dc:creator>Nick Howell</dc:creator><description>&lt;p&gt;Made a few modifications for myself, and also added ?? (the coalescence operator):&lt;/p&gt;
&lt;p&gt;&amp;lt;pre&amp;gt;&lt;/p&gt;
&lt;p&gt;filter Invoke-Ternary ($Predicate, $Then, $Otherwise = $null)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; if($predicate -is [scriptblock]) { $predicate = &amp;amp;$predicate }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; if ($predicate) { &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;if($then -is [ScriptBlock]) { &amp;amp;$then }&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp;else { $then }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; } elseif($otherwise) { &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;if($otherwise -is [ScriptBlock]) { &amp;amp;$otherwise }&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp;else { $otherwise }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;filter Invoke-Coalescence($predicate, $alternative) {&lt;/p&gt;
&lt;p&gt;	if($predicate -is [scriptblock]) { $predicate = &amp;amp;$predicate }&lt;/p&gt;
&lt;p&gt;	Invoke-Ternary $predicate $predicate $alternative&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;set-alias ?: Invoke-Ternary -Option AllScope&lt;/p&gt;
&lt;p&gt;set-alias ?? Invoke-Coalescence -Option AllScope&lt;/p&gt;
&lt;p&gt;&amp;lt;/pre&amp;gt;&lt;/p&gt;</description></item><item><title>re: DYI: Ternary operator</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx#1397125</link><pubDate>Tue, 02 Jan 2007 11:28:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1397125</guid><dc:creator>keith_hill</dc:creator><description>&lt;p&gt;FYI thew equivalent of your Invoke-Coalescence is already in PSCX and is aliased to ?? e.g.:&lt;/p&gt;
&lt;p&gt;$logdir = ?? {$env:logdir} {'C:\Temp'}&lt;/p&gt;
&lt;p&gt;Again if PoSH supported this natively the syntax could be nicer:&lt;/p&gt;
&lt;p&gt;$logdir = $env:logdir ?? 'c:\Temp'&lt;/p&gt;
&lt;p&gt;Although we call the function rather lamely Inovke-NullAlt. &amp;nbsp;Mind if we steal this name for PSCX? &amp;nbsp;:-) &amp;nbsp;BTW, this is a nice equivalent of the KornShell &amp;quot;Foo = ${paramaeter:-word}&amp;quot; functionality.&lt;/p&gt;</description></item><item><title>re: DYI: Ternary operator</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx#1412813</link><pubDate>Fri, 05 Jan 2007 01:13:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1412813</guid><dc:creator>monkeypecker</dc:creator><description>&lt;p&gt;FYI DYI != DIY&lt;/p&gt;
&lt;p&gt;ttfn&lt;/p&gt;
&lt;p&gt;-mp&lt;/p&gt;</description></item><item><title>re: DIY: Ternary operator</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx#1420829</link><pubDate>Sat, 06 Jan 2007 09:22:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1420829</guid><dc:creator>Nick Howell</dc:creator><description>&lt;p&gt;Keith, feel free. If you want to be really picky, you might want to call it Invoke-NullCoalescence (which is probably the most accurate term for it). &lt;/p&gt;
&lt;p&gt;I'm now considering something like this:&lt;/p&gt;
&lt;p&gt;filter Invoke-NullCoalescenceMethod($Object, $Method, [array]$Parameters = @()) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;?: $Object {$item = $Object.PsObject.Members.Item($Method); if($item.Invoke) { $item.Invoke($Parameters) } elseif($item.get_Value -and $Parameters) { $item.Value = $Parameters } else { $item.Value }} $null;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Set-Alias ?. Invoke-NullCoalescenceMethod&lt;/p&gt;
&lt;p&gt;It should work for getters, setters, and methods.&lt;/p&gt;
&lt;p&gt;This is sortof like the null-drilldown offered in Cω (C-omega). It would be really super-fantastic if we could get some of these things in the language. I *really* like the idea of having this: $x?.StartInfo?.CreateNoWindow ?= $true;&lt;/p&gt;
&lt;p&gt;That would just be handy.&lt;/p&gt;</description></item><item><title>Powershell Refactored. – Introduction and Invoke Ternary.</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx#2203821</link><pubDate>Fri, 20 Apr 2007 10:39:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2203821</guid><dc:creator>Powershell Refactored</dc:creator><description>&lt;p&gt;Powershell Refactored. – Introduction and Invoke Ternary. The purpose of this column is to present powershell&lt;/p&gt;
</description></item><item><title>Re: Ternary conditional operator</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx#4978731</link><pubDate>Tue, 18 Sep 2007 16:52:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4978731</guid><dc:creator>Latest Newsgroup Posts</dc:creator><description>&lt;p&gt;Check out Invoke-Ternary here [link] Shay [link]&lt;/p&gt;
</description></item><item><title>Powershell Refactored. – Introduction and Invoke Ternary.</title><link>http://blogs.msdn.com/powershell/archive/2006/12/29/dyi-ternary-operator.aspx#5731438</link><pubDate>Sun, 28 Oct 2007 09:51:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5731438</guid><dc:creator>Karl Prosser (MVP) on Powershell</dc:creator><description>&lt;p&gt;Powershell Refactored. – Introduction and Invoke Ternary. The purpose of this column is to present powershell&lt;/p&gt;
</description></item></channel></rss>