Last active
March 17, 2020 21:00
-
-
Save leogdion/ca917ddb5ade32ee4200475cd743b7bf to your computer and use it in GitHub Desktop.
"Multiply" and Modify Sequences
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
func product<Multiplier, Factor>( | |
_ sequence: [Factor], | |
_ other: [Multiplier] | |
) -> [(Factor, Multiplier)] { | |
return other.flatMap { value in | |
sequence.map { element in | |
(element, value) | |
} | |
} | |
} | |
func product<Multiplier, Factor, Product>( | |
_ sequence: [Factor], | |
_ other: [Multiplier], | |
using closure: (Factor, Multiplier) -> Product | |
) -> [Product] { | |
product(sequence, other).map(closure) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment