Compare commits

..

No commits in common. "16d7190a1de002475e0e0e9e817bc1e0e44cacc9" and "3d82c58a51869ff6134d9eaf3fccb3de0ec74122" have entirely different histories.

3 changed files with 0 additions and 74 deletions

View File

@ -1,48 +0,0 @@
use bad_optics::{lenses::*, prisms::*, traversals::*};
#[derive(Debug, PartialEq, Clone)]
struct MyStruct {
hey: (u8, (u8, [Option<i32>; 5])),
}
fn main() {
// make a lens that accesses `hey` in `MyStruct`
let hey = lens(
|hello: MyStruct| hello.hey,
|mut hello: MyStruct, v| {
hello.hey = v;
hello
},
);
// the thing we want to access
let thing: (MyStruct, &'static str) = (
MyStruct {
hey: (1, (2, [None, Some(1), Some(2), None, Some(4)])),
},
"hello",
);
let array_lens = _0 // access the first element in the tuple
+ hey // access hey
+ _1 // access the second element in the tuple
+ _1; // access the second element in the tuple
assert_eq!(array_lens(thing.clone()).len(), 5);
let lens = array_lens
+ each // access each element of the [Option<i32>; 5] array
+ _Some; // access the ones that are Some;
assert_eq!(lens(thing.clone()), vec![1, 2, 4]);
assert_eq!(
lens(thing, |v| v + 10),
(
MyStruct {
hey: (1, (2, [None, Some(11), Some(12), None, Some(14)])),
},
"hello",
)
);
}

View File

@ -1,12 +0,0 @@
#[macro_export]
macro_rules! field_lens {
($type:ident, $field:ident) => {
lens(
|v: $type| v.$field,
|mut u: $type, v| {
u.$field = v;
u
},
)
};
}

View File

@ -1,5 +1,3 @@
mod fields;
mod identity;
pub use identity::id;
@ -166,18 +164,6 @@ mod tests {
assert_eq!(l(hello), 8);
}
#[test]
fn can_make_lens_for_field() {
// making a lens
let l = crate::field_lens!(Hello, hey);
let hello = Hello { hey: 8 };
assert_eq!(l(hello), 8);
let hello = Hello { hey: 8 };
assert_eq!(l(hello, |v| v + 1), Hello { hey: 9 });
}
#[test]
fn can_make_lens_out_of_funcs() {
// making a lens