mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
add Set.contains
This commit is contained in:
parent
fdf020d89a
commit
5826da028c
6 changed files with 49 additions and 1 deletions
|
@ -210,6 +210,7 @@ mod cli_run {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
#[serial(astar)]
|
||||
fn run_astar_optimized_1() {
|
||||
check_output_with_stdin(
|
||||
|
|
|
@ -95,7 +95,7 @@ pub fn gen_from_mono_module(
|
|||
}
|
||||
|
||||
if name.starts_with("roc_builtins.dict") || name.starts_with("dict.RocDict") {
|
||||
// function.add_attribute(AttributeLoc::Function, attr);
|
||||
function.add_attribute(AttributeLoc::Function, attr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -969,6 +969,14 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
|||
),
|
||||
);
|
||||
|
||||
add_type(
|
||||
Symbol::SET_CONTAINS,
|
||||
top_level_function(
|
||||
vec![set_type(flex(TVAR1)), flex(TVAR1)],
|
||||
Box::new(bool_type()),
|
||||
),
|
||||
);
|
||||
|
||||
// Result module
|
||||
|
||||
// map : Result a err, (a -> b) -> Result b err
|
||||
|
|
|
@ -105,6 +105,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
|
|||
SET_FROM_LIST => set_from_list,
|
||||
SET_INSERT => set_insert,
|
||||
SET_REMOVE => set_remove,
|
||||
SET_CONTAINS => set_contains,
|
||||
SET_WALK=> set_walk,
|
||||
NUM_ADD => num_add,
|
||||
NUM_ADD_CHECKED => num_add_checked,
|
||||
|
@ -229,6 +230,7 @@ pub fn builtin_defs(var_store: &mut VarStore) -> MutMap<Symbol, Def> {
|
|||
Symbol::SET_FROM_LIST => set_from_list,
|
||||
Symbol::SET_INSERT => set_insert,
|
||||
Symbol::SET_REMOVE => set_remove,
|
||||
Symbol::SET_CONTAINS => set_contains,
|
||||
Symbol::SET_WALK => set_walk,
|
||||
Symbol::NUM_ADD => num_add,
|
||||
Symbol::NUM_ADD_CHECKED => num_add_checked,
|
||||
|
@ -2272,6 +2274,11 @@ fn set_remove(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
dict_remove(symbol, var_store)
|
||||
}
|
||||
|
||||
/// Set.remove : Set k, k -> Set k
|
||||
fn set_contains(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
dict_contains(symbol, var_store)
|
||||
}
|
||||
|
||||
/// Set.walk : Set k, (k, accum -> accum), accum -> accum
|
||||
fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let dict_var = var_store.fresh();
|
||||
|
|
|
@ -195,6 +195,37 @@ mod gen_set {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contains() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
fromList : List a -> Set a
|
||||
fromList = \list -> List.walk list (\x, a -> Set.insert a x) Set.empty
|
||||
|
||||
|
||||
Set.contains (fromList [1,3,4]) 4
|
||||
"#
|
||||
),
|
||||
true,
|
||||
bool
|
||||
);
|
||||
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
fromList : List a -> Set a
|
||||
fromList = \list -> List.walk list (\x, a -> Set.insert a x) Set.empty
|
||||
|
||||
|
||||
Set.contains (fromList [1,3,4]) 2
|
||||
"#
|
||||
),
|
||||
false,
|
||||
bool
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_default() {
|
||||
assert_evals_to!(
|
||||
|
|
|
@ -940,6 +940,7 @@ define_builtins! {
|
|||
11 SET_FROM_LIST: "fromList"
|
||||
12 SET_WALK: "walk"
|
||||
13 SET_WALK_USER_FUNCTION: "#walk_user_function"
|
||||
14 SET_CONTAINS: "contains"
|
||||
}
|
||||
|
||||
num_modules: 8 // Keep this count up to date by hand! (TODO: see the mut_map! macro for how we could determine this count correctly in the macro)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue