Ƭ T<A
>: Filterable
<A
>
A Predicate.T<A>
is a unary function which accepts an argument A
and returns a boolean
in order to tell other functions if some conditions are met by A
.
Example
import { Predicate } from 'tiinvo'
const gt10: Predicate.T<number> = x => x > 10;
Since
4.0.0
Name | Description |
---|---|
A |
the type of the passed argument |
▸ and<L
>(...predicates
): <A>(value
: A
) => boolean
Combines two or more predicates in one.
If all predicates are satisfied returns true
, otherwise return false
.
import { Predicate, Num } from 'tiinvo';
const and = Predicate.and(Num.gt(3), Num.lt(10));
and(5) // true
and(2) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
L |
extends T <any >[] |
the list of predicates |
Name | Type |
---|---|
...predicates |
L |
fn
▸ <A
>(value
): boolean
Name | Type |
---|---|
A |
extends unknown |
Name | Type |
---|---|
value |
A |
boolean
▸ eq<A
>(a
, b
): boolean
Returns true if b
strictly equals to a
import { Predicate } from 'tiinvo';
Predicate.eq(0, 10) // false
Predicate.eq(0, 0) // true
Since
4.0.0
Name | Description |
---|---|
A |
the value type |
Name | Type | Description |
---|---|---|
a |
A |
the first value |
b |
A |
the second value |
boolean
▸ eq<A
>(a
): Unary
<A
, boolean
>
Returns true if b
strictly equals to a
import { Predicate } from 'tiinvo';
const eq0 = Predicate.eq(0)
eq0(10) // false
eq0(0) // true
Since
4.0.0
Name | Description |
---|---|
A |
the value type |
Name | Type | Description |
---|---|---|
a |
A |
the first value |
Unary
<A
, boolean
>
▸ guard(x
): x is T<unknown>
Checks if a function could be a predicate
Important: the guard will check only if is a unary function (has only one argument), but will not check it’s returning type
Example
import { Predicate } from 'tiinvo';
Predicate.guard((x: number, b: number) => x + b) // false
Predicate.guard((x: number) => x > 0) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
x |
unknown |
the value to check |
x is T<unknown>
true if a function signature is comparable to a T<any>
, false otherwise
▸ invert<A
>(p
): T
<A
>
Inverts the result of a Predicate
import { Predicate, Num } from 'tiinvo';
const i = Predicate.invert(Num.gt(0))
i(10) // false
i(-1) // true
Since
4.0.0
Name | Description |
---|---|
A |
the predicate’s argument type |
Name | Type | Description |
---|---|---|
p |
T <A > |
the predicate to invert |
T
<A
>
the inverted predicate
▸ neq<A
>(a
, b
): boolean
Returns true if b
is not stricly equal to a
import { Predicate } from 'tiinvo';
Predicate.neq(0, 10) // true
Predicate.neq(0, 0) // false
Since
4.0.0
Name | Description |
---|---|
A |
the value type |
Name | Type | Description |
---|---|---|
a |
A |
the first value |
b |
A |
- |
boolean
▸ neq<A
>(a
): Unary
<A
, boolean
>
Returns true if b
is not stricly equal to a
import { Predicate } from 'tiinvo';
const neq = Predicate.neq(0)
neq(10) // true
neq(0) // false
Since
4.0.0
Name | Description |
---|---|
A |
the value type |
Name | Type | Description |
---|---|---|
a |
A |
the first value |
Unary
<A
, boolean
>
▸ none<L
>(...predicates
): <a>(value
: a
) => boolean
Combines two or more predicates in one. Returns true if none of them is satisfied, otherwise returns false
import { Predicate, Num } from 'tiinvo';
const n = Predicate.none(Num.gt(0), Num.isEven);
n(4) // false
n(5) // false
n(-4) // false
n(-5) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
L |
extends T <any >[] |
the predicates types |
Name | Type |
---|---|
...predicates |
L |
fn
▸ <a
>(value
): boolean
Name | Type |
---|---|
a |
extends unknown |
Name | Type |
---|---|
value |
a |
boolean
▸ or<L
>(...predicates
): <a>(value
: a
) => boolean
Combines two or more predicates in one. Returns true if at least one predicate is satisfied, otherwise returns false
import { Predicate, Num } from 'tiinvo';
const or = Predicate.or(Num.gt(0), Num.isEven);
or(-1) // false
or(1) // true
or(2) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
L |
extends T <any >[] |
the predicates types |
Name | Type |
---|---|
...predicates |
L |
fn
▸ <a
>(value
): boolean
Name | Type |
---|---|
a |
extends unknown |
Name | Type |
---|---|
value |
a |
boolean