fp_library/typeclasses/
clonable_fn.rs

1use crate::{hkt::Kind1L2T, make_type_apply};
2use std::ops::Deref;
3
4/// Abstracts over smart pointers for clonable closures.
5///
6/// This trait is implemented by zero-sized "Brand" types (like `ArcBrand` and `RcBrand`)
7/// to provide a way to construct and type-check function wrappers (`Arc<dyn Fn...>`
8/// or `Rc<dyn Fn...>`) in a generic context.
9pub trait ClonableFn: Kind1L2T + Clone {
10	type Output<'a, A: 'a, B: 'a>: Clone + Deref<Target = dyn 'a + Fn(A) -> B>;
11
12	fn new<'a, A: 'a, B: 'a>(f: impl 'a + Fn(A) -> B) -> <Self as ClonableFn>::Output<'a, A, B>;
13}
14
15make_type_apply!(ApplyFn, ClonableFn, ('a), (A, B), "' -> * -> *");