replace Bool type with Bool=True/False + bugfix

Bool is a type alias for True/False

Bugfix:

[[T] String]
{
  [[T] Int]
  // this would use the outer T (String),
  // but now it correctly uses the inner T (Int).
  [T] 1
}
This commit is contained in:
Mark
2024-08-29 15:04:32 +02:00
parent 7f318d9e1c
commit 385019e43c
11 changed files with 81 additions and 76 deletions

View File

@@ -95,48 +95,3 @@ pub fn to_mers_func_concrete_string_string_to_any(
},
)
}
pub fn to_mers_func_concrete_string_string_to_opt_int(
f: impl Fn(&str, &str) -> Option<isize> + Send + Sync + 'static,
) -> data::function::Function {
to_mers_func_concrete_string_string_to_any(
Type::newm(vec![
Arc::new(data::tuple::TupleT(vec![Type::new(data::int::IntT)])),
Arc::new(data::tuple::TupleT(vec![])),
]),
move |a, b| {
Ok(f(a, b)
.map(|v| Data::one_tuple(Data::new(data::int::Int(v))))
.unwrap_or_else(|| Data::empty_tuple()))
},
)
}
pub fn to_mers_func_concrete_string_string_to_bool(
f: impl Fn(&str, &str) -> bool + Send + Sync + 'static,
) -> data::function::Function {
to_mers_func_concrete_string_string_to_any(Type::new(data::bool::BoolT), move |a, b| {
Ok(Data::new(data::bool::Bool(f(a, b))))
})
}
pub fn to_mers_func_concrete_string_string_to_opt_string_string(
f: impl Fn(&str, &str) -> Option<(String, String)> + Send + Sync + 'static,
) -> data::function::Function {
to_mers_func_concrete_string_string_to_any(
Type::newm(vec![
Arc::new(data::tuple::TupleT(vec![])),
Arc::new(data::tuple::TupleT(vec![
Type::new(data::string::StringT),
Type::new(data::string::StringT),
])),
]),
move |a, b| {
Ok(f(a, b)
.map(|(a, b)| {
Data::new(data::tuple::Tuple(vec![
Data::new(data::string::String(a)),
Data::new(data::string::String(b)),
]))
})
.unwrap_or_else(|| Data::empty_tuple()))
},
)
}