Skip to content

use context manager instead of global variable #1

Open

Description

@etam

Proposed usage:

x = 5

with switch(x) as sw:

    if sw.case(4):
        assert False

    if sw.case(5):
        assert True
        sw.fallthrough()

    if sw.case(lambda x: x > 3):
        assert True

    if sw.case(6):
        assert False

    if sw.default():
        assert False

Activity

  1. etam commented on Feb 9, 2019

    @etam
    Author
  2. masak commented on Mar 14, 2019

    @masak

    Heh, I just dropped into this repo to make the exact same suggestion. 😄

  3. masak commented on Mar 14, 2019

    @masak

    Could probably even shorten sw.case(4) to just case(4) (that is, naming the context variable case and making it callable). sw.default() could then be spelled case.default(), which is a bit charming. Ditto case.fallthrough().

  4. etam commented on Mar 14, 2019

    @etam
    Author
  5. masak commented on Mar 14, 2019

    @masak

    Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions