Skip to content

Commit 2900d64

Browse files
committed
Add Vec2::map
1 parent d772461 commit 2900d64

File tree

1 file changed

+8
-0
lines changed
  • lighthouse-protocol/src/utils

1 file changed

+8
-0
lines changed

lighthouse-protocol/src/utils/vec2.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ impl<T> Vec2<T> {
1717
pub const fn new(x: T, y: T) -> Self {
1818
Self { x, y }
1919
}
20+
21+
/// Maps a function over the vector.
22+
pub fn map<U>(self, mut f: impl FnMut(T) -> U) -> Vec2<U> {
23+
Vec2 {
24+
x: f(self.x),
25+
y: f(self.y),
26+
}
27+
}
2028
}
2129

2230
impl<T> Zero for Vec2<T> where T: Zero {

0 commit comments

Comments
 (0)