Skip to content

Instantly share code, notes, and snippets.

@ivan
Created October 15, 2020 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan/4091d93e67c05159d8743c674ecb6b6a to your computer and use it in GitHub Desktop.
Save ivan/4091d93e67c05159d8743c674ecb6b6a to your computer and use it in GitHub Desktop.
Who does it better?
Elixir
iex(3)> map = %{a: 1, b: 2, c: 3}
%{a: 1, b: 2, c: 3}
iex(4)> map |> Enum.map(fn {k, v} -> {k, v * 2} end) |> Map.new
%{a: 2, b: 4, c: 6}
Rust
use std::collections::HashMap;
fn main() {
let map: HashMap<&str, i32> = [("a", 1), ("b", 2), ("c", 3)].iter().cloned().collect();
dbg!(map.into_iter().map(|(k, v)| (k, v * 2)).collect::<HashMap<&str, i32>>());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment