TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Functional Language Features: Iterators and Closures

62 pointsby s_c_ralmost 5 years ago

5 comments

rectangalmost 5 years ago
&gt; <i>Programming in a functional style often includes using functions as values by passing them in arguments, returning them from other functions, assigning them to variables for later execution, and so forth.</i><p>&gt; ...<p>&gt; <i>Other Rust features, such as pattern matching and enums, which we’ve covered in other chapters, are influenced by the functional style as well.</i><p>What is it about pattern matching and enums that associates them with functional programming? Because going by the description of functional programming above, I don&#x27;t see how they fit in. Is it just that pattern matching and enums were first popularized by certain functional languages?
评论 #23628685 未加载
评论 #23628838 未加载
评论 #23628657 未加载
评论 #23628645 未加载
评论 #23628758 未加载
评论 #23628711 未加载
评论 #23630746 未加载
评论 #23628763 未加载
评论 #23628897 未加载
评论 #23629468 未加载
评论 #23628641 未加载
评论 #23628868 未加载
avodonosovalmost 5 years ago
Why do people post chapters from manuals to HN?
评论 #23630556 未加载
neuroticfishalmost 5 years ago
How are iterators functional language features? They&#x27;re not unique to functional languages and they don&#x27;t require function composition to implement. They&#x27;re present in most popular imperative languages.
评论 #23641020 未加载
_hardwaregeekalmost 5 years ago
I&#x27;ve tried to use iterators and closures in my code, but it&#x27;s not as easy with error handling and lifetimes. Like I could figure out the magic incantation that lets me map over an iterator with a function that returns a result. Or I could write a for loop that pushes to a Vec.<p>Or I could chain an ok_or_else on an Option but ugh now Rust is complaining that I&#x27;m capturing a reference to self. Screw it, I&#x27;ll rewrite it to be an if let with a return. Part of the problem there is that we know an ok_or_else with try! will execute the closure and return if the value is None, but Rust&#x27;s borrow check doesn&#x27;t know that.<p>None of this is Rust&#x27;s fault. It&#x27;s just that it&#x27;s hard to combine ergonomic closures and borrow checking.
gdsdfealmost 5 years ago
as a side note : I hate this ferries thing, just write a good old comment. what&#x27;s wrong with comments?