Skip to content
Open
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
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# Munus PHP website

This website is built using Docusaurus 2, a modern static website generator.
All commit to master are automaticcly deployed to live with [buddy.works](https://buddy.works)
All commit to master are automatically deployed to live with [buddy.works](https://buddy.works)

### Installation
## Installation

```
$ yarn
```bash
yarn
```

### Local Development
## Local Development

```
$ yarn start
```bash
yarn start
```

This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server.

### Build
## Build

```
$ yarn build
```bash
yarn build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

### Deployment
## Deployment

```
$ GIT_USER=<Your GitHub username> USE_SSH=1 yarn deploy
```bash
GIT_USER=<Your GitHub username> USE_SSH=1 yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
61 changes: 53 additions & 8 deletions docs/tuple.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $tuple = Tuple::of('currentTime', new \DateTimeImmutable());
$tuple = Tuple::of(4, 2);
$tuple[0]; // holds 4
$tuple[1]; // holds 2
```
```

Tuples in Munus are immutable. This means that the assignment instruction will end with an exception:

Expand All @@ -31,12 +31,57 @@ $tuple = Tuple::of('Munus', 'is', 'awesome');
$tuple[1] = 'is not'; // UnsupportedOperationException will be thrown
```

## Typing

In Munus, Tuple implementations come with a specified size:

```php
$tuple = Tuple::of('Munus', 'is', 'awesome');
get_class($tuple); // gives Tuple3
```

This approach provides better typing for tuples. You can use generic types to specify the type of each value:

```php
/** @var $tuple Tuple2<string, \DateTimeImmutable> */
$tuple = Tuple::of('currentTime', new \DateTimeImmutable());
```

It also simplifies the validation when you need to ensure you're working with the correct Tuple size.
Instead of doing this:

```php
function process(Tuple $tuple): void
{
if (!in_array($tuple->arity(), [2, 3])) {
// throw exception
}

// processing code
}
```

You can do this:

```php
function process(Tuple2|Tuple3 $tuple): void
{
// processing code
}
```

:::info

The maximum size of a `Tuple` is specified in Tuple::TUPLE_MAX_SIZE constant.

:::

## Methods

- `arity(): int` - returns the number of elements in this tuple
- `toArray(): array` - converts tuple to php classic array
- `append($value): self` - appends new $value to the end and returns new Tuple
- `concat(self $tuple): self` - merge one tuple with other tuple and returns new one
- `apply(callable $transformer)` - transforms tuple with given $transformer, transformer will receive array in the argument
- `map(callable $mapper): self` - maps tuple to other tuple
- `equals(self $tuple): bool` - return true if given tuple contains identical values in identical order
- `arity(): int` - returns the number of elements in this tuple
- `toArray(): array` - converts tuple to php classic array
- `append($value): self` - appends new $value to the end and returns new Tuple
- `concat(self $tuple): self` - merge one tuple with other tuple and returns new one
- `apply(callable $transformer)` - transforms tuple with given $transformer, transformer will receive array in the argument
- `map(callable $mapper): self` - maps tuple to other tuple
- `equals(self $tuple): bool` - return true if given tuple contains identical values in identical order