title: Swift Filter and Map over array of structs
body: <p>I may have this really wrong. Noob. I've recreated what I'm doing in a playground type environment here. Basically the sender is a slider within a UITableView of other sliders. The myData is the underlying data. I want to perform a calculation to all the items of the underlying data EXCEPT the one which corresponds to the sender item. I have no idea if my closure syntax is correct. This is the first time I'm creating one. </p>
  
  <pre><code>// sender comes over as a struct
  struct myStruct {
      var tag: Int = 0
      var value: Float = 0
  }
  let sender = myStruct(tag: 1, value: 199)
  
  // some vars for the calculation
  let globalTotal: Float = 597
  let globalAnotherTotal: Float = 0
  
  // an array of data structs
  struct myDataStruct {
      var name: String = ""
      var value: Float = 0
  }
  var myData: [myDataStruct] = []
  myData.append(myDataStruct(name: "Tom", value: 45.0))
  myData.append(myDataStruct(name: "Dick", value: 16.4))
  myData.append(myDataStruct(name: "Harry", value: 12.3))
  
  // a closure to do the calculation
  var calcOtherVals: (Float, Float) -&gt; (Float) = { (startVal, senderStartVal) in
  
      let remainingStartVals = globalTotal - senderStartVal
      let remainingNewVal = globalTotal - sender.value - globalAnotherTotal
  
      let endVal = ((startVal * (100 / remainingStartVals)) / 100) * remainingNewVal
  
      return endVal
  }
  
  // now need to perform calcOtherVals on all the .value floats in myData EXCEPT the element at position sender.tag hopefully using filter and map
  </code></pre>
  
  <p>So basically I'm trying to use filter and map and the calcOtherVals closure to edit the array of structs in place. I can do this with conditionals and loops and calcOtherVals as a function no problem. Just hoping to do it more elegantly. </p>
  
  <p>QUESTION: As in the code comment, I need to perform <code>calcOtherVals</code> on all the .value floats in myData EXCEPT the element at position <code>sender.tag</code>. How?</p>