mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
move get_shared
function to collections
This commit is contained in:
parent
331a8ed5eb
commit
88ca25e7ee
2 changed files with 23 additions and 24 deletions
|
@ -78,6 +78,28 @@ where
|
||||||
answer
|
answer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Like intersection_with, except for MutMap and specialized to return
|
||||||
|
/// a tuple. Also, only clones the values that will be actually returned,
|
||||||
|
/// rather than cloning everything.
|
||||||
|
pub fn get_shared<K, V>(map1: &MutMap<K, V>, map2: &MutMap<K, V>) -> MutMap<K, (V, V)>
|
||||||
|
where
|
||||||
|
K: Clone + Eq + Hash,
|
||||||
|
V: Clone,
|
||||||
|
{
|
||||||
|
let mut answer = MutMap::default();
|
||||||
|
|
||||||
|
for (key, right_value) in map2 {
|
||||||
|
match std::collections::HashMap::get(map1, &key) {
|
||||||
|
None => (),
|
||||||
|
Some(left_value) => {
|
||||||
|
answer.insert(key.clone(), (left_value.clone(), right_value.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
answer
|
||||||
|
}
|
||||||
|
|
||||||
/// Like im's union, but for MutMap.
|
/// Like im's union, but for MutMap.
|
||||||
pub fn union<K, V>(mut map: MutMap<K, V>, other: &MutMap<K, V>) -> MutMap<K, V>
|
pub fn union<K, V>(mut map: MutMap<K, V>, other: &MutMap<K, V>) -> MutMap<K, V>
|
||||||
where
|
where
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use roc_collections::all::{relative_complement, union, MutMap, SendSet};
|
use roc_collections::all::{get_shared, relative_complement, union, MutMap, SendSet};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_types::boolean_algebra::Bool;
|
use roc_types::boolean_algebra::Bool;
|
||||||
use roc_types::subs::Content::{self, *};
|
use roc_types::subs::Content::{self, *};
|
||||||
use roc_types::subs::{Descriptor, FlatType, Mark, OptVariable, Subs, Variable};
|
use roc_types::subs::{Descriptor, FlatType, Mark, OptVariable, Subs, Variable};
|
||||||
use roc_types::types::{gather_fields, ErrorType, Mismatch, RecordStructure};
|
use roc_types::types::{gather_fields, ErrorType, Mismatch, RecordStructure};
|
||||||
use std::hash::Hash;
|
|
||||||
|
|
||||||
macro_rules! mismatch {
|
macro_rules! mismatch {
|
||||||
() => {{
|
() => {{
|
||||||
|
@ -223,28 +222,6 @@ fn unify_structure(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like intersection_with, except for MutMap and specialized to return
|
|
||||||
/// a tuple. Also, only clones the values that will be actually returned,
|
|
||||||
/// rather than cloning everything.
|
|
||||||
fn get_shared<K, V>(map1: &MutMap<K, V>, map2: &MutMap<K, V>) -> MutMap<K, (V, V)>
|
|
||||||
where
|
|
||||||
K: Clone + Eq + Hash,
|
|
||||||
V: Clone,
|
|
||||||
{
|
|
||||||
let mut answer = MutMap::default();
|
|
||||||
|
|
||||||
for (key, right_value) in map2 {
|
|
||||||
match std::collections::HashMap::get(map1, &key) {
|
|
||||||
None => (),
|
|
||||||
Some(left_value) => {
|
|
||||||
answer.insert(key.clone(), (left_value.clone(), right_value.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
answer
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unify_record(
|
fn unify_record(
|
||||||
subs: &mut Subs,
|
subs: &mut Subs,
|
||||||
pool: &mut Pool,
|
pool: &mut Pool,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue