Last active
May 19, 2017 14:08
-
-
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)]'`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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