Created
          November 30, 2021 19:55 
        
      - 
      
 - 
        
Save Glutexo/04584e98cb0db615b13ced3c7bc4cdfb to your computer and use it in GitHub Desktop.  
    A mutable cell with the simplest API possible
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | _SENTINEL = object() | |
| class Cell: | |
| def __init__(self, value=_SENTINEL): | |
| if value is not _SENTINEL: | |
| self.value = value | |
| def __call__(self, value=_SENTINEL): | |
| if value is not _SENTINEL: | |
| self.value = value | |
| if not hasattr(self, "value"): | |
| raise ValueError("Cell is empty") | |
| return self.value | |
| if __name__ == "__main__": | |
| cell = Cell() | |
| # cell() | |
| cell("x") | |
| print(cell()) | |
| cel = Cell("y") | |
| print(cel()) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment