Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float Like A Butterfly: Introduce PresenceBox, TryBox, and ParamTryBox. #1876

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Commits on Jul 7, 2017

  1. Introduce PresenceBox, TryBox, and ParamTryBox.

    These three intermediary types allow APIs and consumers of boxes to indicate
    that they expect a particular subset of Box types. This is useful to restrict
    types to what is expected, while still being able to interoperate with
    APIs designed to interact with many all Box types.
    
    For example, you can declare that a function expectes a PresenceBox to ensure
    that interactors guarantee either a Full or Empty is passed. Or, you can
    specify that your function returns a TryBox so callers only need to worry about
    handling a Full or a Failure. Lastly, ParamTryBox allows indicating that a
    given situation will only get a Full or a ParamFailure with a particular error
    type.
    
    A lot of tests and additional API conversions are required to fully bring this
    vision to fruition, but this is the foundation for that work.
    Shadowfiend committed Jul 7, 2017
    Configuration menu
    Copy the full SHA
    9b09bf1 View commit details
    Browse the repository at this point in the history

Commits on Jul 8, 2017

  1. Make pass and $ return self.type.

    This allows us to make sure that we don't lose the specific type of the Box
    when doing a pass operation. This was less important when the only supertype
    was `Box`, but now that we can have the more specific `PresenceBox`, `TryBox`,
    and `ParamTryBox`, preserving those supertypes is more important.
    Shadowfiend committed Jul 8, 2017
    Configuration menu
    Copy the full SHA
    b1b3035 View commit details
    Browse the repository at this point in the history

Commits on Jul 9, 2017

  1. Tweak collect and collectFirst typing for PresenceBox.

    In particular, collect and collectFirst will always return a PresenceBox when
    invoked on a PresenceBox. This is not the case for the other subtypes.
    Shadowfiend committed Jul 9, 2017
    Configuration menu
    Copy the full SHA
    671a958 View commit details
    Browse the repository at this point in the history
  2. Tweak typing in flatMap, map, flatten, filter, filterNot, isA, and asA.

    In particular, cases where each of these can guarantee a subtype of Box have
    reimplementations that do so.
    
    PresenceBox also adds a specialization of withFilter, which is used in for
    comprehensions, that ensures that typing carries through.
    Shadowfiend committed Jul 9, 2017
    Configuration menu
    Copy the full SHA
    592e94e View commit details
    Browse the repository at this point in the history
  3. Adjust typing on a few Box singleton functions.

    These can now have more specific types.
    Shadowfiend committed Jul 9, 2017
    Configuration menu
    Copy the full SHA
    f22afbe View commit details
    Browse the repository at this point in the history
  4. Scaladoc updates for a few places in Box.

    Also added a blurb to the Box scaladocs regarding the Box subtypes.
    Shadowfiend committed Jul 9, 2017
    Configuration menu
    Copy the full SHA
    9b906eb View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    90ad32f View commit details
    Browse the repository at this point in the history

Commits on Aug 5, 2017

  1. Drop attempt at flatten type specialization.

    Due to the way Scala resolves method overloads with implicit parameters, I
    haven't been able to find a good way of defining that a TryBox that contains a
    TryBox should flatten to a TryBox, and a PresenceBox that contains a
    PresenceBox should flatten to a PresenceBox. Unfortunately Scala seems to
    resolve the overload of flatten based solely on class hierarchy and number of
    parameters, and then fails the compile if it can't plug the proper implicits
    in, rather than using the available implicit evidence to choose between
    overloads. Since we rely entirely on implicit evidence to know what we can do
    with the contained type of the box, there's no way (that I could find) to
    express diverging return types based on the contained type :(
    
    Instead, TryBox and PresenceBox each have their own flattenTry and
    flattenPresence methods, respectively, which will only compile if their
    contents match the container type. This means the caller has to choose the
    appropriate one to call, but at least it ensures you *can* flatten that way if
    you really want to.
    Shadowfiend committed Aug 5, 2017
    Configuration menu
    Copy the full SHA
    a8f1402 View commit details
    Browse the repository at this point in the history

Commits on Sep 17, 2017

  1. Configuration menu
    Copy the full SHA
    ccb507b View commit details
    Browse the repository at this point in the history
  2. Add preliminary BoxTypingSpec.

    This spec is designed to test that Box's various methods produce the expected
    resulting types.
    Shadowfiend committed Sep 17, 2017
    Configuration menu
    Copy the full SHA
    f20573c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    12012bd View commit details
    Browse the repository at this point in the history

Commits on Sep 25, 2017

  1. Fix Full flatMap for ParamTryBox.

    The existing definition wasn't actually catching for all ParamTryBoxes.
    Shadowfiend committed Sep 25, 2017
    Configuration menu
    Copy the full SHA
    69bfa97 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    86f3503 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    8679ca2 View commit details
    Browse the repository at this point in the history
  4. Move flattenPresence/flattenTry specs into their own examples.

    Also add some scaladocs to those two methods.
    Shadowfiend committed Sep 25, 2017
    Configuration menu
    Copy the full SHA
    28d5d57 View commit details
    Browse the repository at this point in the history
  5. Drop ??? definitions of collect and map.

    We do this by dropping the concrete definitions of these two methods in Box,
    preferring instead to lean 100% on late binding to resolve the correct concrete
    definition of the method based on the concrete type it is being invoked on.
    Shadowfiend committed Sep 25, 2017
    Configuration menu
    Copy the full SHA
    4b8fb17 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f58523f View commit details
    Browse the repository at this point in the history