I\'m trying to write an extension for the Matrix
example from the book, slightly tweaked to be generic.
I\'m trying to write a method called getRow
Joe Groff suggested to wrap the result in SequenceOf
:
extension Matrix {
func getRow(index: Int) -> SequenceOf {
return SequenceOf(map(0..self.columns, { self[index, $0] }))
}
}
Indeed, this works but we had to wrap map
result into a helper class which differs from how I do it in C#.
I have to admit I don't yet understand why Sequence
and Generator
use typealias
and aren't generic protocols (like IEnumerable
in C#). There is an interesting ongoing discussion about this distinction so I'll leave a few links for a curious mind: