This file contains hidden or 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 createMorseCodeText(from encodedMessage: EncodedMessage) -> String { | |
let transformation = MorseTransformation( | |
dot: ".", | |
dash: "-", | |
markSeparator: "", | |
symbolSeparator: " ", | |
termSeparator: "\n") | |
let characters = transformation.apply(to: encodedMessage) | |
return characters.joinWithSeparator("") | |
} |
This file contains hidden or 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
enum TransmissionState { | |
typealias RelativeDuration = Int | |
case On(RelativeDuration) | |
case Off(RelativeDuration) | |
static func createStates(from encodedMessage: EncodedMessage) | |
-> [TransmissionState] { | |
let transformation = MorseTransformation( | |
dot: TransmissionState.On(1), | |
dash: TransmissionState.On(3), |
This file contains hidden or 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
/// Converts an `EncodedMessage` to an alternate representation. | |
struct MorseTransformation<T> { | |
let dot, dash, markSeparator, symbolSeparator, termSeparator: T | |
func apply(to encodedMessage: EncodedMessage) -> [T] { | |
return encodedMessage.apply(self) | |
} | |
} | |
private extension EncodedMessage { |
OlderNewer