@@ -256,6 +256,19 @@ where
256
256
257
257
/// Returns a reference to the first element of the array, or `None` if it
258
258
/// is empty.
259
+ ///
260
+ /// # Example
261
+ ///
262
+ /// ```rust
263
+ /// use ndarray::Array3;
264
+ ///
265
+ /// let mut a = Array3::<f64>::zeros([3, 4, 2]);
266
+ /// a[[0, 0, 0]] = 42.;
267
+ /// assert_eq!(a.first(), Some(&42.));
268
+ ///
269
+ /// let b = Array3::<f64>::zeros([3, 0, 5]);
270
+ /// assert_eq!(b.first(), None);
271
+ /// ```
259
272
pub fn first ( & self ) -> Option < & A >
260
273
where
261
274
S : Data ,
@@ -269,6 +282,19 @@ where
269
282
270
283
/// Returns a mutable reference to the first element of the array, or
271
284
/// `None` if it is empty.
285
+ ///
286
+ /// # Example
287
+ ///
288
+ /// ```rust
289
+ /// use ndarray::Array3;
290
+ ///
291
+ /// let mut a = Array3::<f64>::zeros([3, 4, 2]);
292
+ /// *a.first_mut().unwrap() = 42.;
293
+ /// assert_eq!(a[[0, 0, 0]], 42.);
294
+ ///
295
+ /// let mut b = Array3::<f64>::zeros([3, 0, 5]);
296
+ /// assert_eq!(b.first_mut(), None);
297
+ /// ```
272
298
pub fn first_mut ( & mut self ) -> Option < & mut A >
273
299
where
274
300
S : DataMut ,
0 commit comments