change over to not take a ref, rename id to identity
This commit is contained in:
parent
7bac8ee9ec
commit
d76541fbc5
4 changed files with 17 additions and 9 deletions
|
@ -12,10 +12,13 @@ macro_rules! make_tuples {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl< $($t,)* > LensOver<( $($t,)* )> for _0 {
|
impl< $($t,)* > LensOver<( $($t,)* )> for _0 {
|
||||||
fn over(
|
fn over<F>(
|
||||||
mut tup: ($($t,)*),
|
mut tup: ($($t,)*),
|
||||||
f: &dyn Fn(Self::Field) -> Self::Field
|
f: F
|
||||||
) -> ( $($t,)* ) {
|
) -> ( $($t,)* )
|
||||||
|
where
|
||||||
|
F: FnOnce(Self::Field) -> Self::Field
|
||||||
|
{
|
||||||
tup.0 = f(tup.0);
|
tup.0 = f(tup.0);
|
||||||
tup
|
tup
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,10 @@ impl<T> LensView<T> for T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<T> LensOver<T> for T {
|
impl<T> LensOver<T> for T {
|
||||||
fn over(thing: T, f: &dyn Fn(Self::Field) -> Self::Field) -> T {
|
fn over<F>(thing: T, f: F) -> T
|
||||||
|
where
|
||||||
|
F: FnOnce(Self::Field) -> Self::Field,
|
||||||
|
{
|
||||||
f(thing)
|
f(thing)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
mod id;
|
mod identity;
|
||||||
pub use id::id;
|
pub use identity::id;
|
||||||
mod first;
|
mod first;
|
||||||
pub use first::_0;
|
pub use first::_0;
|
||||||
|
|
|
@ -5,10 +5,12 @@ pub trait LensView<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LensOver<T>: LensView<T> {
|
pub trait LensOver<T>: LensView<T> {
|
||||||
fn over(thing: T, f: &dyn Fn(Self::Field) -> Self::Field) -> T;
|
fn over<F>(thing: T, f: F) -> T
|
||||||
|
where
|
||||||
|
F: FnOnce(Self::Field) -> Self::Field;
|
||||||
|
|
||||||
fn set(thing: T, v: Self::Field) -> T {
|
fn set(thing: T, v: Self::Field) -> T {
|
||||||
Self::over(thing, &|_| v)
|
Self::over(thing, |_| v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +20,7 @@ pub fn view<T, L: LensView<T>>(_lens: L, thing: T) -> L::Field {
|
||||||
pub fn set<T, L: LensOver<T>>(_lens: L, thing: T, v: L::Field) -> T {
|
pub fn set<T, L: LensOver<T>>(_lens: L, thing: T, v: L::Field) -> T {
|
||||||
L::set(thing, v)
|
L::set(thing, v)
|
||||||
}
|
}
|
||||||
pub fn over<T, L: LensOver<T>>(_lens: L, thing: T, f: &dyn Fn(L::Field) -> L::Field) -> T {
|
pub fn over<T, L: LensOver<T>>(_lens: L, thing: T, f: impl FnOnce(L::Field) -> L::Field) -> T {
|
||||||
L::over(thing, f)
|
L::over(thing, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue