Example: let's create thisβ¦
[ "π", "π§", "π", "π", "π", "π",
"π", "π", "π", "π", "π", "π ",
"π", "π‘", "π", "π’", "π", "π£",
"π", "π€", "π", "π₯", "π", "π¦",
"π"
]
β¦with this:
Array( π°.prefix(25) )
We'll do that with a simple example of a use case for the thread title question.
It is possible to reduce branch count by changing what happens in the next
of a sequence, like so:
var π°: AnySequence<String> {
func addHalfHour(toHour hour: UInt32) -> UInt32 {
hour + 12
}
func getNextHalfHour(afterHour hour: UInt32) -> UInt32 {
getNext = getNextHour
return addHalfHour(toHour: hour)
}
let twelve: UInt32 = 128347
var getNext: ( (UInt32) -> UInt32 )! = getNextHalfHour
func getNextHour(after30 halfHour: UInt32) -> UInt32 {
getNext = getNextHalfHour
return
( halfHour == addHalfHour(toHour: twelve)
? twelve
: halfHour
)
- 11
}
return .init(
sequence(first: twelve) { getNext($0) }
.lazy
.map { String(Unicode.Scalar($0)!) }
)
}
Given that getNext
will always mutate itself, is there a solution (without introducing a branch) to avoid having to make it optional?