Skip to content

Instantly share code, notes, and snippets.

@dmcyk
Last active May 19, 2017 14:08
Show Gist options
  • Save dmcyk/e233ff6309e377d33634763b54528e13 to your computer and use it in GitHub Desktop.
Save dmcyk/e233ff6309e377d33634763b54528e13 to your computer and use it in GitHub Desktop.
Works fine with Swift 3, but with 4 (17 May 2017 snapshot) I get following error `'map' produces '[T]', not the expected contextual result type '[(Element)]'`
public extension Array where Element: FloatingPoint {
func normalized(scale: Element) -> [Element] {
guard let maxVal = self.max(), let minVal = self.min() else {
return []
}
let diff = maxVal - minVal
return self.map { val in
((val - minVal) / diff) * scale
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment