TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

List Comprehension in Swift

56 点作者 DaNmarner超过 7 年前

4 条评论

59nadir超过 7 年前
I really dislike the proposed way to do this. If this is &quot;Swifty&quot;, give me something else.<p>The Haskell list comprehension made sense to me the first time I saw it, but there is no way I&#x27;d know what the mess in the article was doing until someone explained to me.<p>Design has to come first. You can&#x27;t just go with what&#x27;s &quot;Swifty&quot; if that doesn&#x27;t convey what&#x27;s happening in a reasonable fashion.
评论 #15891303 未加载
评论 #15891243 未加载
Someone超过 7 年前
<i>List</i> comprehension is a bad idea, IMO. They were an improvement over not having anything like it, but python has improved over it (<a href="https:&#x2F;&#x2F;wiki.python.org&#x2F;moin&#x2F;Generators" rel="nofollow">https:&#x2F;&#x2F;wiki.python.org&#x2F;moin&#x2F;Generators</a>)<p>⇒ <i>Generator expressions</i> are the way to go. They would give you the sequence of elements without generating the (potentially enormous) data structure.<p>From there, methods to reify the items in a sequence would give you your list, array, or dictionary, where needed.<p>So, for Swift, I wouldn’t use<p><pre><code> Array(1..&lt;5, 3..&lt;5) { ($0, $1) } </code></pre> but the slightly longer<p><pre><code> Array(for i in 1..&lt;5, j in 3..&lt;5 yield (i,j)) </code></pre> I’m not sure that is easy to fit in the existing parser, though. If it can be fit in, I would allow that code in ‘normal’ nested for loops, too.
评论 #15892387 未加载
thewayfarer超过 7 年前
&gt; (Can’t wait until we can have variadic generic parameters!)<p>This.
评论 #15890594 未加载
评论 #15891839 未加载
ralfd超过 7 年前
Can someone explain the n modulo operation to me?
评论 #15891152 未加载