txt: ## proxy.md
  class Proxy
  
  Item container with custom storage and retrieval
  
  ```raku
  class Proxy {}
  ```
  
  A Proxy is an object that allows you to set a hook that executes whenever a value is retrieved from a container (`FETCH`) or when it is set (`STORE`). Please note that `Proxy` can introduce mutability at places where it would break behavior, e.g. in [`Hash`](/type/Hash) keys.
  
  To create a container that returns twice what was stored in it, you do something like this:
  
  ```raku
  sub double() is rw {
      my $storage = 0;
      Proxy.new(
          FETCH => method ()     { $storage * 2    },
          STORE => method ($new) { $storage = $new },
      )
  }
  my $doubled := double();
  $doubled = 4;
  say $doubled;       # OUTPUT: «8␤»
  
  ```
  
  # [Methods](#class_Proxy "go to top of document")[§](#Methods "direct link")
  
  ## [method new](#class_Proxy "go to top of document")[§](#method_new "direct link")
  
  ```raku
  method new(:&FETCH!, :&STORE! --> Proxy:D)
  ```
  
  Creates a new `Proxy` object. `&FETCH` is called with one argument (the proxy object) when the value is accessed, and must return the value that the fetch produces. `&STORE` is called with two arguments (the proxy object, and the new value) when a new value is stored in the container.
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `Proxy`
  
  
  
  raku-type-graph
  
  
  
  Proxy
  Proxy
  
  
  Any
  Any
  
  
  Proxy->Any
  
  
  
  Mu
  Mu
  
  
  Any->Mu
  
  [Expand chart above](/assets/typegraphs/Proxy.svg)
  