Uploaded image for project: 'Mesos'
  1. Mesos
  2. MESOS-3226

Introduce an Either type.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Accepted
    • Major
    • Resolution: Unresolved
    • None
    • None
    • stout
    • 5

    Description

      We currently don't have an abstraction in stout to capture the notion of having a container with many types and a single value. For example, in our abstractions like Try, rather than being able to say Either<Error, Value> t we must encode two Options (Option<Error>, Option<T>) with the implicit invariant that exactly one will be set.

      This also comes in handy in many other places in the code. Note that we have the ability to (1) use C++11 unions now, as well as (2) use boost's variant directly instead of introducing Either. However, creating a named union every time this is needed is verbose, and unions require that we externally track which member is set. For variant, we already use this (e.g. json.hpp), but we can benefit from the better naming as Either.

      Many languages expose Either as having only two values, left and right. I'd propose making this two or more, as is the case with variant.

      Attachments

        Activity

          People

            Unassigned Unassigned
            bmahler Benjamin Mahler
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: