News for hackers. Stuff that matters.
Re:Swift: The joy of sequences by jdmichal on Wednesday June 08, 2016 @04:57PM (#11865604)
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...

Re:Swift: The joy of sequences by fleshweasel on Wednesday June 08, 2016 @06:24PM (#11866164)
Beyond being a little more explicit about the generator semantics, it's just noisier. "Self.Iterator.Element" is a lot of noise compared to "T".

At the moment, I feel these sequence extensions are just allowing people to write toy programs with slightly less boilerplate, and are accomplishing little as far as improving our ability to produce useful software.