I am creating an extension to Collection
which returns a SubSequence
. However, if the function's condition isn't valid I want to return an empty SubSequence
instead of nil.
How can I return an empty SubSequence
in an extension to Collection
?
// basic example: extension Collection { func myFunction(condition: Bool) -> SubSequence { guard condition else { return *EmptySubSequence* } ... } }
This would be very easy if I just did an extension on a concrete type, but before I limit my extension to a specific type, I would like to know if it can apply to Collection
itself.
The best I've found is prefix(0)
will return a SubSequence
of length 0.
没有评论:
发表评论