Skip to content

Commit 2f2dc9f

Browse files
committed
Change focus to transformation functions
1 parent 625a4cb commit 2f2dc9f

File tree

12 files changed

+110
-436
lines changed

12 files changed

+110
-436
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
### 0.1.0 (2016-01-11)
4+
5+
* Changed: Rename library to `Transform`
6+
* Changed: Use function instead of static methods
7+
* Removed: `Filter::isNull()`
8+
* Removed: `Filter::notNull()`
9+
* Removed: `Filter::isSameAs($expected)`
10+
* Removed: `Filter::notSameAs($expected)`
11+
* Removed: `Filter::isLike($expected)`
12+
* Removed: `Filter::notLike($expected)`
13+
* Removed: `Filter::hasMethodReturning(string $methodName, $expected, bool $strict = true)`
14+
* Removed: `Filter::notHasMethodReturning(string $methodName, $expected, bool strict = true)`
15+
316
### 0.0.1 (2016-01-10)
417

518
* Added: `Filter::isNull()`

README.md

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,47 @@
11
# Predicate
22

3-
Predicate is a simple library which aims to make using PHP's `array_map` and
4-
`array_filter` functions a more pleasent experience - and resulting in cleaner
5-
code.
3+
Predicate is a simple library which aims to make using PHP's `array_map`
4+
function a more pleasent experience - and resulting in cleaner code.
65

7-
Predicate is a collection of helper functions for common filter and transform
8-
actions.
6+
Predicate is a collection of helper functions for common transform actions.
7+
8+
For a great companion library of predicates to make your `array_filter` code also look great, see [Pentothal](https://github.com/Giuseppe-Mazzapica/Pentothal).
99

1010
## Example
1111

1212
Take this code:
1313

1414
```php
15-
$customers = array_filter(
16-
$allUsers,
15+
$names = array_map(
1716
function ($user) {
18-
return $user->getType() === 'customer';
19-
}
17+
return $user->getName();
18+
},
19+
$allUsers
2020
);
2121
```
2222

23-
Using predicate this looks like this:
23+
Using transform this looks like this:
2424

2525
```php
26-
$customer = array_filter($allUsers, Filter::hasMethodReturning('getType', 'customer'));
26+
$names = array_map(T\callMethod('getName'), $allUsers);
2727
```
2828

2929
## Installation
3030

3131
Using composer:
3232

33-
`composer require tomphp/predicate`
34-
35-
## Filters
36-
37-
All filters are defined as static methods on `TomPHP\Predicate\Filter`.
38-
39-
So far the following filters are provided:
40-
41-
```
42-
isNull()
43-
notNull()
44-
isSameAs($expected)
45-
notSameAs($expected)
46-
isLike($expected)
47-
notLike($expected)
48-
hasMethodReturning(string $methodName, $expected, bool strict = true)
49-
notHasMethodReturning(string $methodName, $expected, bool strict = true)
50-
```
51-
52-
By convention: all functions starting with `is` are negated by replacing the
53-
p`is` with `not`, and all function staring with `has` are negated prefixing
54-
`not`.
55-
56-
## Transforms
57-
58-
Transforms are for use with `array_map`.
59-
60-
Transforms are used to replace code like this:
61-
62-
```php
63-
$names = array_map(
64-
function ($user) {
65-
return $user->getName();
66-
},
67-
$allUsers
68-
);
69-
```
33+
`composer require tomphp/transform`
7034

71-
With code like this:
35+
## Transformations
7236

7337
```php
74-
$names = array_map(Transform::callMethod('getName'), $allUsers);
38+
use TomPHP\T as T;
7539
```
7640

77-
### Transform::callMethod($methodName)
41+
### T\callMethod($methodName)
7842

7943
```php
80-
Transform::classMethod('getName');
44+
T\classMethod('getName');
8145

8246
// Generates:
8347

@@ -86,10 +50,10 @@ function ($object) {
8650
}
8751
```
8852

89-
### Transform::getEntry($name)
53+
### T\getEntry($name)
9054

9155
```php
92-
Transform::getEntry('name');
56+
T\getEntry('name');
9357

9458
// Generates:
9559

@@ -99,7 +63,7 @@ function ($array) {
9963
```
10064

10165
```php
102-
Transform::getEntry(['user', 'name']);
66+
T\getEntry(['user', 'name']);
10367

10468
// Generates:
10569

@@ -108,10 +72,10 @@ function ($array) {
10872
}
10973
```
11074

111-
### Transform::argumentTo($callable)
75+
### T\argumentTo($callable)
11276

11377
```php
114-
Transform::getEntry('strtolower');
78+
T\getEntry('strtolower');
11579

11680
// Generates:
11781

composer.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
2-
"name": "tomphp/predicate",
2+
"name": "tomphp/transform",
33
"description": "A set tools to make array_map and array_filter more friendly.",
44
"type": "library",
5+
"keywords": [
6+
"function",
7+
"functional programming",
8+
"map",
9+
"array_map",
10+
"transform"
11+
],
12+
"homepage": "https://github.com/tomphp/Transform",
513
"license": "MIT",
614
"authors": [
715
{
@@ -10,9 +18,9 @@
1018
}
1119
],
1220
"autoload": {
13-
"psr-4": {
14-
"TomPHP\\Predicate\\": "src/"
15-
}
21+
"files": [
22+
"src/transform.php"
23+
]
1624
},
1725
"require": {},
1826
"require-dev": {

src/Filter.php

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)