Comment

Comment by majewsky

This is pretty much the closure syntax used by Go, and it's one of its biggest issues (IMHO). Even if you had map/filter/etc. methods on slices, it would still look like:

  squares := numbers.
      filter(func(x int) bool { return x >= 0 }).
      map(func(x int) int { return x * x })
With what I understand to be your suggested Rust syntax, this would still me:

  let squares: Vec<_> = numbers.iter()
      .filter(fn(x: i64) -> bool { x >= 0 })
      .map(fn(x: i64) -> i64 { x * x })
      .collect();
which is a lot of noise compared to

  let squares: Vec<_> = numbers.iter().filter(x => x >= 0).map(x => x * x).collect();
parent majewsky 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton