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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Elixir Streams

152 点作者 pgr0ss将近 10 年前

3 条评论

phamilton将近 10 年前
When people say Elixir is just syntactic sugar on top of erlang I point them to Stream and Enum. It's a great example of how polymorphism via protocols is an enabler for powerful designs.
评论 #9683955 未加载
doomrobo将近 10 年前
Interesting to see this as a novel thing in another ecosystem. Rust actually uses &quot;stream&quot; manipulation as a default way of dealing with things that might otherwise be expressed as full data structures. For example, the equivalent to one of the code snippets in the article would be:<p>BufReader::new(File::open(&quot;myfile.txt&quot;).unwrap())<p>.lines()<p>.enumerate()<p>.map(|(i, line)| format!(&quot;{}: {}&quot;, i, line.unwrap()))<p>.take(1)<p>.next().unwrap()<p>(formatted for non-monospace font readability). Note the .unwrap() is where error handling should normally happen.
评论 #9683586 未加载
_nato_将近 10 年前
I wonder what the Erlang equivalent would look like (passing around data that are funs)?
评论 #9682543 未加载
评论 #9683415 未加载