Lustre is a more protocol-oriented variant of the nascent Result pattern in Swift 2.0, as seen commonly in the community.

Lustre provides a protocol, EitherType, as well as two concrete implementations, Either<T, U> and Result<T>.

Why the Protocol?

A good chunk of the time, you'll be using the concrete Either and Result. Like the design of Swift's map and flatMap, the default implementations of map and flatMap return a Result.

Making your own EitherType is useful for API design, when you want to model specific scenarios but also get the convenience of an Either API. This includes types not strictly represented by an enum with two cases, or a wrapper of another result, etc.

It might be advantageous to make your own concrete type conforming to EitherType and give it extra functionality. Consider an idiomatic JSON enum type. A JSON parser might return a JSONResult. On that type, you could have convenience methods to return a Result<String> if the JSON value is the string case, etc. But by conforming to EitherType, it is also mostly interchangeable with any Result instance.

The need for this repo can go away if extensions with where cases are added to generics to parallel protocol extensions. See rdar://21901489. Until then, Lustre is a scalable, usable, and idiomatic version of the pattern you already know and more-or-less tolerate. Unlike previous versions of Lustre, there are no weird hacks, no Any, and no syntactical difference from the common-case Result type.

Availability

Lustre, on this branch, is intended for Swift 2.0. The old hacky version for Swift 1.2 is still preserved.

What's up with the name?

Result => Lustre. It's an anagram.