Created
October 15, 2020 21:58
-
-
Save ivan/4091d93e67c05159d8743c674ecb6b6a to your computer and use it in GitHub Desktop.
Who does it better?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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