# Helpers for storage of data

## The `Storage` object

    ### 1. Create a `Storage` object:
    my_storage <- Storage$new()

    # 2. Add elements along with identifiers:
    my_storage$
      add(42, c("number", "rational"))$
      add(pi, c("number", "!rational"))$
      add("fear of black cats", c("text", "!rational"))$
      add("wearing a seat belt", c("text", "rational"))$
      add(mean, "function")

    # 3. What elements are stored?
    print(my_storage)
    #> number of elements: 5
    #> identifiers used: number rational text function

    # 4. Extract elements based on identifiers:
    my_storage$get("rational")
    #> [[1]]
    #> [1] 42
    #>
    #> [[2]]
    #> [1] "wearing a seat belt"
    my_storage$get("!rational")
    #> [[1]]
    #> [1] 3.141593
    #>
    #> [[2]]
    #> [1] "fear of black cats"
    my_storage$get(c("text", "!rational"))
    #> [[1]]
    #> [1] "fear of black cats"
    my_storage$get("all") # get all elements
    #> [[1]]
    #> [1] 42
    #>
    #> [[2]]
    #> [1] 3.141593
    #>
    #> [[3]]
    #> [1] "fear of black cats"
    #>
    #> [[4]]
    #> [1] "wearing a seat belt"
    #>
    #> [[5]]
    #> function (x, ...)
    #> UseMethod("mean")
    #> <bytecode: 0x000002cd1ceaaa28>
    #> <environment: namespace:base>
    my_storage$get(c("text", "!text"))
    #> list()
    my_storage$get(c("text", "!text"), logical = "or")
    #> [[1]]
    #> [1] 42
    #>
    #> [[2]]
    #> [1] 3.141593
    #>
    #> [[3]]
    #> [1] "fear of black cats"
    #>
    #> [[4]]
    #> [1] "wearing a seat belt"
    #>
    #> [[5]]
    #> function (x, ...)
    #> UseMethod("mean")
    #> <bytecode: 0x000002cd1ceaaa28>
    #> <environment: namespace:base>

    # 5. Extract elements based on ids:
    my_storage$get(ids = 4:5)
    #> [[1]]
    #> [1] "wearing a seat belt"
    #>
    #> [[2]]
    #> function (x, ...)
    #> UseMethod("mean")
    #> <bytecode: 0x000002cd1ceaaa28>
    #> <environment: namespace:base>
    my_storage$get(ids = 4:5, id_names = TRUE) # add the ids as names
    #> $`4`
    #> [1] "wearing a seat belt"
    #>
    #> $`5`
    #> function (x, ...)
    #> UseMethod("mean")
    #> <bytecode: 0x000002cd1ceaaa28>
    #> <environment: namespace:base>