MCPcopy Create free account
hub / github.com/hashintel/hash / try_map_with_option

Function try_map_with_option

libs/@local/hashql/core/src/intern/beef.rs:827–844  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

825 #[test]
826 #[expect(clippy::integer_division_remainder_used)]
827 fn try_map_with_option() {
828 let heap = Heap::new();
829 let interner = InternSet::new(&heap);
830 let original = interner.intern_slice(&[1, 2, 3, 4, 5]);
831
832 // All transformations succeed
833 let mut beef = Beef::new(original);
834 let result: Option<()> = beef.try_map(|x| Some(x * 3));
835 assert!(result.is_some());
836 assert_eq!(beef.as_slice(), &[3, 6, 9, 12, 15]);
837
838 // Transformation fails on even numbers
839 let mut beef = Beef::new(original);
840 let result: Option<()> = beef.try_map(|x| if x % 2 == 0 { None } else { Some(x * 10) });
841 assert!(result.is_none());
842 // The first value should be transformed, then it should fail on 2
843 assert_eq!(beef.as_slice(), &[10, 2, 3, 4, 5]);
844 }
845
846 #[test]
847 fn try_map_multiple_calls() {

Callers

nothing calls this directly

Calls 2

intern_sliceMethod · 0.80
try_mapMethod · 0.80

Tested by

no test coverage detected