Skip to content

Commit e63cca4

Browse files
committed
Simplify the grid function
1 parent 56d0b30 commit e63cca4

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

src/figure.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::{Error, IntoError, axes::Axes};
44
use numpy::{PyArray1, PyArray2, PyArrayMethods};
55
use pyo3::{intern, prelude::*, sync::PyOnceLock, types::PyDict};
6-
use std::path::Path;
6+
use std::{array, path::Path};
77

88
include!("macros.rs");
99

@@ -26,16 +26,8 @@ pub fn subplots<const R: usize, const C: usize>()
2626
fn grid<const R: usize, const C: usize, U>(
2727
f: impl Fn(usize, usize) -> U
2828
) -> [[U; C]; R] {
29-
let mut r = 0;
30-
[(); R].map(|_| {
31-
let mut c = 0;
32-
let row = [(); C].map(|_| {
33-
let y = f(r, c);
34-
c += 1;
35-
y
36-
});
37-
r += 1;
38-
row
29+
array::from_fn(|r| {
30+
array::from_fn(|c| f(r, c))
3931
})
4032
}
4133

0 commit comments

Comments
 (0)