I'm not very familiar with Swift. If I'm understanding right, the `prefix` function being defined is equivalent to LINQ's `TakeWhile` [0]. If so, the C# version seems much easier to read to me:
public static IEnumerable<T> TakeWhile<T>(
this IEnumerable<T> source,
Func<T, bool> predicate) {
foreach(T value in source) {
if (predicate(value))
yield return value;
else
yield break;
}
}
Of course, there's a bunch of compiler magic going on here that's basically creating a state machine, which seems to be explicit in the Swift version. Are there any similar features in Swift to C#'s `yield`? If not, are any on the road map?[0] https://msdn.microsoft.com/en-us/library/bb534804%28v=vs.110...