title: How to apply reduce to chunks (coming from a borrowed reference to an array)?
body: <p>How can I make use of functional patterns without incurring in borrowing problems? The solution proposed by the compiler leads to another error (<code>expected array </code>[u8; 3]<code>, found '&amp;[u8]'</code>) and it goes on from one error to another different error, indefinitely.
  Some related code seem overly complicated for such a simple task like in this <a href="https://stackoverflow.com/a/37926547/9681577">other question</a>.</p>
  <pre><code>use reduce::Reduce;
  
  /// Take an array representing a sequence of 3-tuples and fold it through an arbitrary sandwich logic.
  fn sandwich(lst: &amp;[u8])-&gt;[u8; 3]{
      lst.chunks(3).reduce(|x, y| [x[0], y[1], x[0]]).unwrap()
  }
  /*
  3  |     lst.chunks(3).reduce(|x, y| [x[0], y[1], x[0]]).unwrap()
     |                                 ^^^^^^^^^^^^^^^^^^
     |                                 |
     |                                 expected `&amp;[u8]`, found array `[u8; 3]`
     |                                 help: consider borrowing here: `&amp;[x[0], y[1], x[0]]`
  */
  </code></pre>
  <p>The best compilable code I could write was this convoluted one, giving up <a href="https://crates.io/crates/reduce" rel="nofollow noreferrer">reduce</a> at all:</p>
  <pre><code>fn sandwich2(lst: &amp;[u8])-&gt;[u8; 3]{
      let mut r: [u8; 3] = lst[..].try_into().unwrap();
      for i in (3..lst.len()).step_by(3) {
          let y = &amp;lst[i..i + 3];
          r = [r[0], y[1], r[0]];
      }
      r
  }
  </code></pre>
  <p>Please note that sandwich is just an example to illustrate the problem (that does nothing actually smart). I expect an external much more complex function instead of that lambda.</p>