Skip to content

Commit

Permalink
Simplify simple operations and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dazet committed Jan 7, 2022
1 parent c996770 commit 30d0d82
Show file tree
Hide file tree
Showing 37 changed files with 1,908 additions and 581 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,54 @@ $stringsArray = Wrap::iterable($range(0, 10))
});
```

### `NumberValue`

Object wrapping number (float or int).

```php
<?php

use GW\Value\Numberable\Math;
use GW\Value\Wrap;

$number = Wrap::number(100)
->add(20)
->subtract(1)
->multiply(2)
->divide(3)
->modulo(100)
->calculate(Math::sqrt())
->round(2);
// ...

$formattedNumber = $number->format(2, '.', ',');

```

### `NumbersArray`

Object wrapping array of numbers wrapped in NumberValue.

```php
<?php

use GW\Value\NumberValue;
use GW\Value\Wrap;

$numbers = Wrap::numbersArray([1, 2, 3, 4]);

$sum = $numbers->sum()->format(2)->toString();
$min = $numbers->min()->format(2)->toString();
$max = $numbers->max()->format(2)->toString();
$avg = $numbers->average()->format(2)->toString();

$customSum = $numbers->reduceNumber(
fn(NumberValue $sum, NumberValue $next): NumberValue => $sum->add($next->round()),
0
);

```

## Documentation

For full methods reference and more examples see [here](./docs/examples.md).
Expand Down
Loading

0 comments on commit 30d0d82

Please sign in to comment.