Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 107 additions & 1 deletion docs/packages/quant/core/AbstractList.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Reference
## Definition
Namespace: `Quant\Core`

`AbstractList` Represents a strongly typed list with methods for manipulating and searching.
`AbstractList<T>` Represents a strongly typed list with methods for manipulating and searching its items.

```php
class AbstractList<T>: \Quant\Core\Contract\Arrayable,
Expand All @@ -19,6 +19,9 @@ class AbstractList<T>: \Quant\Core\Contract\Arrayable,
\Countable
```

### Type Parameters
- `T`: The type of the items maintained by the list.

## Example

```php
Expand Down Expand Up @@ -73,5 +76,108 @@ $listC->findBy(fn (Entity $item): bool => $item->getValue() !== "a")->toArray();

## Remarks

- Items can be added to the list using the array shorthand syntax `$list[] = $item;`; If an item is added to the list
that is not of type `T`, a `TypeError` is thrown.
- [`equals`](#equals) compares items using [`compareItems`](#compareitems) iff `T` does not implement [`Equatable`](/docs/packages/quant/core/contract/equatable) or [`Comparable`](/docs/packages/quant/core/contract/comparable)

## Methods

### compareItems
Compares two instances of `T`, and returns `true` if two items reference the same item.

:::note
This method is used by [equals](#equals) and should be overriden when custom logic is required and `$lft` / `$rgt` do not not implement [`Equatable`](/docs/packages/quant/core/contract/equatable) or [`Comparable`](/docs/packages/quant/core/contract/comparable) .
:::

```php
protected function compareItems(T $lft, T $rgt): bool
```

#### Parameters
- `T $lft`
- `T $rgt`

#### Returns
- `bool`

### equals
Compares two lists for equality. If `T` implements [`Equatable`](/docs/packages/quant/core/contract/equatable), `T`'s `equals`-method will be used.
If `T` implements [`Comparable`](/docs/packages/quant/core/contract/comparable), `T`'s `compareTo` will be used and two items will be considered
`equal` if `compareTo` returns `0` for two items.

`compareTo` will only be called if `T` does not implement `Equatable`.

If `T` implements neither of the two, **this** list calls [`compareItems`](#compareitems).


```php
public function equals(Equatable $target): bool
```

#### Parameters
- `Equatable $target`<br /> The list **this** list should be compared to.

#### Returns
- `bool` <br /> `true` if list `$target` is considered to be equal to **this** list


### findType
Returns a new `AbstractList<T>` with all entries matched by `$findFn`, or `null` if no items where matched.

```php
public function findType(callable $findFn): null|AbstractList<T>
```

#### Parameters
- `callable $findFb`<br /> Callback function that takes an instance of `T` as an argument and returns `bool`: `true` indicates a match.

#### Returns
- `AbstractList<T>` <br /> A new list containing the matched items.



### getType
Returns the class name of `T`.

```php
abstract public function getType(): string
```

#### Returns
- `string`



### map
Applies the function to this data and returns **this** list.

#### Parameters
- `callable $mapFn`<br />A function that takes an instance of `T` as the argument and returns the same instance of `T`

#### Returns
- `AbstractList<T>`


### make
Factory method for creating instances of `AbstractList<T>`

```php
public static function make(T ...$items): AbstractList<T>
```

#### Parameters
- `T ...$items` <br /> An arbitrary number of arguments each representing an instance of `T`

#### Returns
- `AbstractList<T>`


### peek
Returns the element at the head of the `AbstractList`, or `null` if the list is empty.

```php
public function peek(): mixed
```

#### Returns
- `?<T>` <br /> `null` if the list is empty, otherwise the element of type `<T>` found at the head of the list.
1 change: 1 addition & 0 deletions docs/packages/quant/core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Low-level API providing contracts, base classes and commonly-used functionality.

| Name | Description |
|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| [AbstractList](/docs/packages/quant/core/abstractlist) | A strongly typed list maintaining objects by a numeric index. |
| [AccessorTrait](/docs/packages/quant/core/trait/accessortrait) | Provides accessor automation for object properties attributed with `#[Setter]` and/or `#[Getter]`. |
| [Arrayable](/docs/packages/quant/core/contract/arrayable) | Indicates the availability of an array-representative for the implementing class' instance. |
| [Comparable](/docs/packages/quant/core/contract/comparable) | Implements a total order on objects of `T : Comparable`. |
Expand Down
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const sidebars = {
label: 'Core',
link: {type: 'doc', id: "packages/quant/core/quant_core"},
items: [
"packages/quant/core/abstractlist",
{
type: 'category',
label: 'Contract',
Expand Down