Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #3

Merged
merged 5 commits into from
Feb 9, 2018
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
72 changes: 1 addition & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,78 +67,8 @@ echo tail([1, 2, 3]); // => [2, 3]

API
---
All functions is unitary, exception when the second argument is optional. It has constants to help you to work with point-free style.

```
all()
allPass()
always()
any()
anyPass()
append()
contains()
compose()
cond()
divide()
drop()
equals()
filter()
find()
flatten()
gt()
gte()
has()
head()
id()
ifElse()
isEmpty()
indexOf()
init()
join()
last()
lt()
lte()
map()
memoize()
merge()
multiply()
none()
not()
partial()
pipe()
prepend()
prop()
props()
reduce()
replace()
slice()
split()
tail()
take()
toString()
typeof()
unless()
when()
```

#### Constants from native functions

```
keys
values
flip
sum
isNull
isInt
isFloat
isNumeric
isString
isBool
isScalar
isArray
isObject
isCallable
```
[**Full API Documentation**](docs/index.md)

Thanks
------
Expand Down
222 changes: 222 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# API
All functions is unitary, exception when the second argument is optional. It has constants to help you to work with point-free style.

+ [`all()`](#all)
+ [`allPass()`](#allpass)
+ [`always()`](#always)
+ [`any()`](#any)
+ [`anyPass()`](#anypass)
+ [`append()`](#append)
+ [`contains()`](#contains)
+ compose()
+ cond()
+ divide()
+ drop()
+ equals()
+ filter()
+ find()
+ flatten()
+ gt()
+ gte()
+ has()
+ head()
+ id()
+ ifElse()
+ isEmpty()
+ indexOf()
+ init()
+ join()
+ last()
+ lt()
+ lte()
+ map()
+ memoize()
+ merge()
+ multiply()
+ none()
+ not()
+ partial()
+ pipe()
+ prepend()
+ prop()
+ props()
+ reduce()
+ replace()
+ slice()
+ split()
+ tail()
+ take()
+ toString()
+ typeof()
+ unless()
+ when()

#### Constants from native functions

+ keys
+ values
+ flip
+ sum
+ isNull
+ isInt
+ isFloat
+ isNumeric
+ isString
+ isBool
+ isScalar
+ isArray
+ isObject
+ isCallable

-------

### `all()`

```php
function all(callable $pred): \Closure;
```

`function => closure([array]) => boolean`

```php
use const Prelude\isScalar;
use function Prelude\all;

$even = function ($n) {
return $n % 2 === 0;
};

all($even)([2, 4, 6, 8, 10, 12]); // true
all(isScalar)([1, 2, 3, 4]); // true
all(isScalar)([1, 2, [], 4]); // false
```

### `allPass()`

```php
function allPass(array $preds): \Closure;
```

function => closure => boolean

```php
use function Prelude\partial;
use function Prelude\allPass;
use function Prelude\get;
use function Prelude\has;

$placeholders = [
'to' => 'xxx@xxx.com',
'from' => 'xxx@xxx.com'
];

$propEq = partial(function ($k, $v, array $xss) {
return ($xss[$k] ?? false) === $v;
});

$y = allPass([has('from'), has('to')]);
$y($placeholders); // true

$x = allPass([$propEq('rank', 'Q'), $propEq('suit', '♠︎')]);

$x(['rank' => 'Q', 'suit' => '♠︎']); // true
$x(['rank' => 'Q', 'suit' => '♣︎︎']); // false
```

### `always()`

```php
function always($x): \Closure
{
return function () use ($x) {
return $x;
};
}
```

### `any()`

```php
function any(callable $pred): \Closure;
```

`function => closure([array]) => boolean`

```php
use function Prelude\any;

$isEven = function ($n) { return $n % 2 === 0; };
$isOdd = function ($n) { return $n % 2 === 1; };

any($isEven)([1, 3, 4, 5, 7]); // true
any($isEven)([1, 3, 5, 7]); // false

any($isOdd)([1, 3, 5, 7]); // true
any($isOdd)([2, 4, 6]); // false

any('is_array')([2, []]); // true
any('is_array')(['s', 'x']); // false
```

### `anyPass()`

```php
function anyPass(array $preds): \Closure;
```
[array] => closure(callable) => boolean

```php
use function Prelude\anyPass;
use function Prelude\partial;
use function Prelude\equals;
use function Prelude\has;

$gt = partial(function ($a, $b) { return $a > $b; });
$gte = anyPass([$gt(3), equals(3)]);

$gte(2); // true
$gte(3); // true
$gte(4); // false

$has = anyPass([has('user'), has('mobile')]);
$has(['user' => '']); // true
$has(['mobile' => '']); // true
$has([]); // false

```

### `append()`

```php
function append($x): \Closure;
```

`any => closure([array]) => [array]`

```php
use function Prelude\append;

append('tests')(['write', 'more']); // => ['write', 'more', 'tests'];

$append = append(['tests']);
$append(['write', 'more']); // => ['write', 'more', ['tests']];
```

### `contains()`

```php
function contains($x): \Closure;
```

`any => closure([array]) => bool`

```php
use function Prelude\Contains;

$ls = ['name' => 'James'];
contains('James')($ls); // true
contains('Kirk')($ls); // false

$nums = [10, 20, 30];
contains(10)($nums); // true
```