<div dir="ltr">You could also create a “Range” protocol with “lowerBound” and “upperBound” properties. Conform all the range types to it, and make your function take generic over the protocol.<div><br></div><div>Nevin</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 12, 2016 at 7:21 PM, Hooman Mehr via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div dir="auto" style="word-wrap:break-word"><div>I recommend having explicit precondition and reducing repetition like this:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">import</span><span style="font-variant-ligatures:no-common-ligatures"> Foundation</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> random(from range: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">CountableRange</span><span style="font-variant-ligatures:no-common-ligatures"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">>) -> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="m_6497328186317167931webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">precondition</span><span style="font-variant-ligatures:no-common-ligatures">(range.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">count</span><span style="font-variant-ligatures:no-common-ligatures"> > </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">0</span><span style="font-variant-ligatures:no-common-ligatures">,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">"The range can't be empty."</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d">random</span><span style="font-variant-ligatures:no-common-ligatures">(from: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">CountableClosedRange</span><span style="font-variant-ligatures:no-common-ligatures">(range))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> random(from range: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">CountableClosedRange</span><span style="font-variant-ligatures:no-common-ligatures"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">>) -> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="m_6497328186317167931webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> lowerBound = range.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">lowerBound</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> upperBound = range.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">upperBound</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="m_6497328186317167931webkit-block-placeholder"></div></span><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">precondition</span><span style="font-variant-ligatures:no-common-ligatures">(upperBound - lowerBound < </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">UInt32</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">max</span><span style="font-variant-ligatures:no-common-ligatures">),</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">"The range </span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">\</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">range</span><span style="font-variant-ligatures:no-common-ligatures">) is too wide. It shouldn't be wider than </span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">\</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">UInt32</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">max</span><span style="font-variant-ligatures:no-common-ligatures">)."</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">)</span></div><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="m_6497328186317167931webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">return</span><span style="font-variant-ligatures:no-common-ligatures"> lowerBound + </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">arc4random_uniform</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">UInt32</span><span style="font-variant-ligatures:no-common-ligatures">(<wbr>upperBound - lowerBound + </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures">)))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> r1 = </span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d">random</span><span style="font-variant-ligatures:no-common-ligatures">(from: </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">4</span><span style="font-variant-ligatures:no-common-ligatures"> ..< </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">8</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> r2 = </span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d">random</span><span style="font-variant-ligatures:no-common-ligatures">(from: </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">6</span><span style="font-variant-ligatures:no-common-ligatures"> ... </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">8</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">Once we have the new <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md" target="_blank">improved Integer protocols</a> in place, you will be able to make it generic to support all integer types. (It is possible now, but too messy to be worth doing.)</span></div><div><div class="h5"><div><br></div><br><div><blockquote type="cite"><div>On Oct 12, 2016, at 1:23 PM, Adriano Ferreira via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br class="m_6497328186317167931Apple-interchange-newline"><div><div style="word-wrap:break-word">Hi there!<div><br></div><div>Ole Begeman offers <a href="https://oleb.net/blog/2016/09/swift-3-ranges/" target="_blank">here</a> (take a look at the bottom of the page) an interesting consideration about converting between half-open and closed ranges.</div><div><br></div><div>As of now, it seems the way to go is by overloading…</div><div><br></div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">import</span><span style="font-variant-ligatures:no-common-ligatures"> Foundation</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> random(from range: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Range</span><span style="font-variant-ligatures:no-common-ligatures"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">>) -> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> lowerBound = range.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">lowerBound</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> upperBound = range.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">upperBound</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="m_6497328186317167931webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">return</span><span style="font-variant-ligatures:no-common-ligatures"> lowerBound + </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">arc4random_uniform</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">UInt32</span><span style="font-variant-ligatures:no-common-ligatures">(<wbr>upperBound - lowerBound)))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> random(from range: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">ClosedRange</span><span style="font-variant-ligatures:no-common-ligatures"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">>) -> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> lowerBound = range.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">lowerBound</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> upperBound = range.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">upperBound</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="m_6497328186317167931webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">return</span><span style="font-variant-ligatures:no-common-ligatures"> lowerBound + </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">arc4random_uniform</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">UInt32</span><span style="font-variant-ligatures:no-common-ligatures">(<wbr>upperBound - lowerBound + </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures">)))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> r1 = </span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d">random</span><span style="font-variant-ligatures:no-common-ligatures">(from: </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">4</span><span style="font-variant-ligatures:no-common-ligatures"> ..< </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">8</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> r2 = </span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d">random</span><span style="font-variant-ligatures:no-common-ligatures">(from: </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">6</span><span style="font-variant-ligatures:no-common-ligatures"> ... </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">8</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div></div><div><br></div><div><br></div><div>Cheers,</div><div><br></div><div>— A</div><div><br><div><blockquote type="cite"><div>On Oct 12, 2016, at 6:21 AM, Jean-Denis Muys via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br class="m_6497328186317167931Apple-interchange-newline"><div><div style="word-wrap:break-word">Hi,<div><br></div><div>I defined this:</div><div><br></div><div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> random(from r: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Range</span><span style="font-variant-ligatures:no-common-ligatures"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">>) -> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> from = r.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">lowerBound</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> to = r.</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">upperBound</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;min-height:16px"><span style="font-variant-ligatures:no-common-ligatures"> </span><br class="m_6497328186317167931webkit-block-placeholder"></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> rnd = </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">arc4random_uniform</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">UInt32</span><span style="font-variant-ligatures:no-common-ligatures">(to-<wbr>from))</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">return</span><span style="font-variant-ligatures:no-common-ligatures"> from + </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">(rnd)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div><br></div><div>so that I can do:</div><div><br></div><div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> testRandomValue = </span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d">random</span><span style="font-variant-ligatures:no-common-ligatures">(from: </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">4</span><span style="font-variant-ligatures:no-common-ligatures">..<</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">8</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div></div><div><br></div><div>But this will not let me do:</div><div><br></div><div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> otherTestRandomValue = random(from: </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">4</span><span style="font-variant-ligatures:no-common-ligatures">...</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">10</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div></div><div><br></div><div>The error message is a bit cryptic:</div><div><br></div><div>“No ‘…’ candidate produce the expected contextual result type ‘Range<Int>’”</div><div><br></div><div>What is happening is that 4…10 is not a Range, but a ClosedRange.</div><div><br></div><div>Of course I can overload my function above to add a version that takes a ClosedRange.</div><div><br></div><div>But this is not very DRY.</div><div><br></div><div>What would be a more idiomatic way?</div><div><br></div><div>Thanks,</div><div><br></div><div>Jean-Denis</div><div><br></div></div>______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div>______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></div></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>