mapm¶
In [ ]:
open rust.rust_operators
rust¶
hash_map¶
In [ ]:
nominal hash_map k v =
`(
global "#if FABLE_COMPILER\n[<Fable.Core.Erase; Fable.Core.Emit(\"std::collections::HashMap<$0, $1>\")>]\n#endif\ntype std_collections_HashMap<'K, 'V> = class end"
$'' : $'std_collections_HashMap<`k, `v>'
)
b_tree_map¶
In [ ]:
nominal b_tree_map k v =
`(
global "#if FABLE_COMPILER\n[<Fable.Core.Erase; Fable.Core.Emit(\"std::collections::BTreeMap<$0, $1>\")>]\n#endif\ntype std_collections_BTreeMap<'K, 'V> = class end"
$'' : $'std_collections_BTreeMap<`k, `v>'
)
new_hash_map¶
In [ ]:
inl new_hash_map () : hash_map _ _ =
!\($'"std::collections::HashMap::new()"')
new_b_tree_map¶
In [ ]:
inl new_b_tree_map () : b_tree_map _ _ =
!\($'"std::collections::BTreeMap::new()"')
get¶
In [ ]:
inl get forall k v. (key : k) (map : hash_map k v) : optionm'.option' v =
inl key = join key
!\\(map, $'"std::collections::HashMap::get(&$0, &!key).map(|x| x).cloned()"')
insert¶
In [ ]:
inl insert forall k v. (key : k) (value : v) (map : hash_map k v) : optionm'.option' v =
inl key = join key
!\($'"let mut !map = !map"')
!\($'"std::collections::HashMap::insert(&mut !map, !key, !value)"')
map'¶
In [ ]:
inl map' forall k v w. (fn : v -> w) (map : hash_map k v) : hash_map k w =
!\\((map, fn), $'"$0.into_iter().map(|(k, v)| (k, $1(v))).collect()"')
hash_map_count¶
In [ ]:
inl hash_map_count forall k v. (map : hash_map k v) : i32 =
!\\(map, $'"$0.count()"')
from_vec¶
In [ ]:
inl from_vec forall k v. (vec : am'.vec (k * v)) : hash_map k v =
!\($'"std::collections::HashMap::from_iter(!vec)"')
from_vec_pairs¶
In [ ]:
inl from_vec_pairs forall k v. (vec : am'.vec (pair k v)) : hash_map k v =
!\($'"std::collections::HashMap::from_iter(!vec.iter().map(|x| x.as_ref()).map(|&(ref k, ref v)| (k.clone(), v.clone())))"')
b_tree_map_from_vec_pairs¶
In [ ]:
inl b_tree_map_from_vec_pairs forall k v. (vec : am'.vec (pair k v)) : b_tree_map k v =
!\($'"std::collections::BTreeMap::from_iter(!vec.iter().map(|x| x.as_ref()).map(|&(ref k, ref v)| (k.clone(), v.clone())))"')
from_array¶
In [ ]:
inl from_array forall k v. (array : array_base (k * v)) : hash_map k v =
array |> am'.to_vec |> from_vec
from_list¶
In [ ]:
inl from_list forall k v. (list : list (k * v)) : hash_map k v =
inl (a list) : _ i32 _ = list |> listm.toArray
list |> am'.to_vec |> from_vec
to_vec¶
In [ ]:
inl to_vec forall k v. (map : hash_map k v) : am'.vec (k * v) =
!\\(map, $'"$0.into_iter().map(|(k, v)| (k, v)).collect::<Vec<_>>()"')
fsharp¶
map¶
In [ ]:
nominal map k v = $'Map<`k, `v>'
item¶
In [ ]:
inl item forall k v. (k : k) (map : map k v) : v =
$'!map.[!k]'
of_array¶
In [ ]:
inl of_array forall k v. (array : a _ (k * v)) : map k v =
$'!array |> Array.map (fun (struct (a, b)) -> a, b) |> Map.ofArray'