(.using
  [library
   [lux {"-" list}
    ["$" documentation {"+" documentation:}]
    [control
     ["<>" parser
      ["<[0]>" code]]]
    [data
     ["[0]" text {"+" \n}
      ["%" format {"+" format}]]]
    [macro
     [syntax {"+" syntax:}]
     ["[0]" code]
     ["[0]" template]]]]
  [\\library
   ["[0]" /]])

(documentation: (/.Array it)
  "Mutable arrays.")

(documentation: /.empty
  "An empty array of the specified size."
  [(empty size)])

(documentation: /.size
  ""
  [(size array)])

(documentation: /.read!
  ""
  [(read! index array)])

(documentation: /.write!
  "Mutate the array by writing a value to the specified index."
  [(write! index value array)])

(documentation: /.delete!
  "Mutate the array by deleting the value at the specified index."
  [(delete! index array)])

(documentation: /.contains?
  ""
  [(contains? index array)])

(documentation: /.update!
  "Mutate the array by updating the value at the specified index."
  [(update! index transform array)])

(documentation: /.upsert!
  (format "Mutate the array by updating the value at the specified index."
          \n "If there is no value, update and write the default value given.")
  [(upsert! index default transform array)])

(documentation: /.copy!
  "Writes the contents of one array into the other."
  [(copy! length src_start src_array dest_start dest_array)])

(documentation: /.occupancy
  "Finds out how many cells in an array are occupied."
  [(occupancy array)])

(documentation: /.vacancy
  "Finds out how many cells in an array are vacant."
  [(vacancy array)])

(documentation: /.filter!
  "Delete every item of the array that fails to satisfy the predicate."
  [(filter! p xs)])

(documentation: /.example
  "Yields the first item in the array that satisfies the predicate."
  [(example p xs)])

(documentation: /.example+
  "Just like 'example', but with access to the index of each value."
  [(example+ p xs)])

(documentation: /.clone
  "Yields a shallow clone of the array."
  [(clone xs)])

(documentation: /.of_list
  ""
  [(of_list xs)])

(documentation: /.list
  (format "Yields a list with every non-empty item in the array."
          \n "Can use the optional default value when encountering an empty cell in the array.")
  [(list {.#None} array)
   (list {.#Some default} array)])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Array
             ..empty
             ..size
             ..read!
             ..write!
             ..delete!
             ..contains?
             ..update!
             ..upsert!
             ..copy!
             ..occupancy
             ..vacancy
             ..filter!
             ..example
             ..example+
             ..clone
             ..of_list
             ..list
             ($.default /.type_name)
             ($.default /.equivalence)
             ($.default /.monoid)
             ($.default /.functor)
             ($.default /.mix)
             ($.default /.every?)
             ($.default /.any?)]
            []))
