diff --git a/public/css/pages.css b/public/css/pages.css index 2ef51dd..ad99572 100644 --- a/public/css/pages.css +++ b/public/css/pages.css @@ -49,7 +49,7 @@ background: var(--code-theme-bg-color); } -.markdown a { +.markdown > p > a { color: var(--c-link); text-decoration: underline; } diff --git a/src/components/docs/CodeMin.astro b/src/components/docs/CodeMin.astro new file mode 100644 index 0000000..85b1777 --- /dev/null +++ b/src/components/docs/CodeMin.astro @@ -0,0 +1,9 @@ +--- +import { native_highlighter } from "../../lexer/highlighter"; + +const { thpcode, href } = Astro.props; + +const native_html = await native_highlighter(thpcode); +--- + + diff --git a/src/components/docs/Warning.astro b/src/components/docs/Warning.astro new file mode 100644 index 0000000..0b41d45 --- /dev/null +++ b/src/components/docs/Warning.astro @@ -0,0 +1,4 @@ +
+
+
+You can also declare an index along with the value:
+
+
+
+```sh
+item 0: red
+item 1: green
+item 2: blue
+```
### Access
@@ -241,6 +272,17 @@ THP arrays don't have destructuring, since the values can all be `null`.
If you know that the number of elements is fixed and valid, use Tuples instead.
+### Operators
+
+While PHP allows using certain operators with arrays, THP disallows that.
+Methods that perform comparisons should be used instead.
+
+
+### Assignment
+
+// TODO: Detail that assignment of arrays is copy on write
+
+
## Methods
In the parameters, self
is the array to operate on.
@@ -254,25 +296,26 @@ In the parameters, self
is the array to opera
- fun
- filter
- [
- T
- ]
- (
-
- self
- ,
-
- (T) -> Bool callback,
-
- )->
- Array
- [
- T
- ]
-
self
is the array to opera
- fun - push - [ - T - ] - ( - self - , T ...elements) -> - Int -
+self
is the array to opera
- fun - pop - [ - T - ] - ( - self - ) -> - T -
+ Array[T]
+`} />
+
+## Parameters
+
+- `self`: The callee.
+- `Array[T]... arrays`: Multiple arrays to concatenate the current one to.
+
+## Return value
+
+`Array[T]`: A new array that contains the elements from all arrays.
+
+
+## Description
+
+Concatenates the elements of the callee and the elements of each array in the
+variable `array`. These values are returned in a new array.
+
+If called without any aditional array it returns a new array with the elements
+of `self`.
+
+The returned array is a new one. However, if the elements of the callee and the
+parameters are references, the returned array will contain references that point
+to the same memory. This is important if, for example, the arrays contain other
+arrays or objects.
+
+## Examples
+
+Example concatenating 2 arrays:
+
+
+
+Example concatenating 3 arrays:
+
+
+
+Example concatenating without any other array. In this case
+`first` and `result` are different arrays:
+
+
+
+Example concatenating an empty array with a filled array:
+
+
+
+
+## PHP interop
+
+This method is directly compiled to `array_merge`. Since THP guarantees that
+arrays only have numbers as keys, this will never produce invalid values due
+to merging with an array with string keys.
+
+If the arrays contain invalid keys (negative values, out of bounds) the merge
+is performed based on the insertion order, not the keys order, and the resulting
+array will have correct keys.
+
+```php
+$array_1 = [2 => "a", 0 => "b"];
+$array_2 = [1 => "c"];
+
+var_dump(array_merge($array_1, $array_2));
+```
+
+```out
+array(3) {
+ [0]=> string(1) "a"
+ [1]=> string(1) "b"
+ [2]=> string(1) "c"
+}
+```
+
+
+
diff --git a/src/pages/api/std/Array/filter.md b/src/pages/api/std/Array/filter.md
deleted file mode 100644
index 052af3d..0000000
--- a/src/pages/api/std/Array/filter.md
+++ /dev/null
@@ -1,6 +0,0 @@
----
-layout: ../../../../layouts/ApiLayout.astro
----
-
-# Array.filter
-