Skip to content

Commit

Permalink
Added O::dissoc()
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Apr 13, 2021
1 parent da8646d commit 2deb4d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,18 @@ $point2d = new stdClass();
$point2d->x = 10;
$point2d->y = 20;

$point3d = O::assoc('z', 30, $point2d);
$point3d = O::assoc('z', 30, $point2d); // {"x": 10, "y": 20, "z": 30}
```

- **dissoc** - removes a key from an object

```php
$point3d = new stdClass();
$point3d->x = 10;
$point3d->y = 20;
$point3d->z = 30;

$point2d = O::dissoc('z', 30, $point3d); // {"x": 10, "y": 20}
```

## Future plans
Expand Down
6 changes: 6 additions & 0 deletions src/O.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ public static function assoc(string $key, $value, object $data): object {
$data->{$key} = $value;
return $data;
}

// O::dissoc('foo')
public static function dissoc(string $key, object $data): object {
unset($data->{$key});
return $data;
}
}

0 comments on commit 2deb4d4

Please sign in to comment.