▸ check(a, m): void
Asserts that a specified condition is true, otherwise throws an error with the given message
Example
import { Assert } from 'tiinvo'
Assert.check(true, 'will not throw') // does not throw
Assert.check(false, 'yup it throws') // throws
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
boolean |
if true it throws |
m |
string |
the error message |
void
▸ check(a): Unary<boolean, void>
Returns a unary function which accepts a boolean which asserts that the argument is true, otherwise throws an error with the given message
Example
import { Assert } from 'tiinvo'
const somecheck = Assert.check(`It's not true!`);
somecheck(true) // undefined
somecheck(false) // throws new Error(`It's not true!`)
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the error message |
Unary<boolean, void>
the unary function which returns
▸ checkResult(a, b): T<boolean>
Asserts that a specified condition is true and returns it, otherwise returns Result.Err with the given errorMessage
Example
import { Assert } from 'tiinvo'
Assert.checkResult(true, 'will not throw') // true
Assert.checkResult(false, 'yup it throws') // Error("yup it throws")
Assert.checkResult('will not throw')(true) // true
Assert.checkResult('yup it throws')(false) // Error("yup it throws")
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
boolean |
the condition |
b |
string |
the error message |
T<boolean>
Result.Ok<true> if a is trueResult.Err otherwise▸ checkResult(a): Unary<boolean, T<boolean>>
Returns a unary function which asserts that a specified condition is true
returning it, otherwise returns Result.Err with the given error message a
Example
import { Assert } from 'tiinvo'
Assert.checkResult('will not throw')(true) // true
Assert.checkResult('yup it throws')(false) // Error("yup it throws")
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the error message |
the unary function which returns
Result.Ok<true> if a is trueResult.Err otherwise▸ make<a>(p, m): Unary<a, void>
Creates a check function starting from a Predicate.t<a> and a message.
Example
import { Assert, Num } from 'tiinvo'
const check0 = Assert.make(Num.isEven, 'number is not even')
check0(10) // does not throw
check0(11) // throws "number is not even"
check1(10) // does not throw
check1(11) // throws "number 11 is not even"
Since
4.0.0
| Name | Description |
|---|---|
a |
the type passed to the predicate and to the mappable functor (if any) |
| Name | Type | Description |
|---|---|---|
p |
T<a> |
the predicate |
m |
string | Mappable<a, string> |
the error message or the mappable functor |
Unary<a, void>
the asserting unary function which returns
void if it’s ok▸ make<a>(p): Unary<T<a>, Unary<a, void>>
Creates a check function starting from a Predicate.t<a> and a message.
Example
import { Assert, Num } from 'tiinvo'
const check1 = Assert.make(Num.isEven, x => `number ${x} is not even`)
check0(10) // does not throw
check0(11) // throws "number is not even"
check1(10) // does not throw
check1(11) // throws "number 11 is not even"
Since
4.0.0
| Name | Description |
|---|---|
a |
the type passed to the predicate and to the mappable functor (if any) |
| Name | Type | Description |
|---|---|---|
p |
string | Mappable<a, string> |
the error message or the mappable functor |
the asserting unary function which returns
Result.Ok<true> if a is trueResult.Err otherwise▸ makeResult<A>(p, m): Unary<A, T<boolean>>
Creates a check function starting from a Predicate.t<a> and a message.
Example
import { Assert, Num } from 'tiinvo'
const check0 = Assert.makeResult(Num.isEven, 'number is not even')
const check1 = Assert.makeResult(Num.isEven, x => `number ${x} is not even`)
check0(10) // true
check0(11) // Error("number is not even")
check1(10) // true
check1(11) // Error("number 11 is not even")
Since
4.0.0
| Name | Description |
|---|---|
A |
the type passed to the predicate and to the mappable functor (if any) |
| Name | Type | Description |
|---|---|---|
p |
T<A> |
the asserting predicate |
m |
string | Mappable<A, string> |
the error message or the mappable functor |
the asserting function which returns
Result.Ok<A> if a is trueResult.Err otherwise▸ makeResult<A>(p): Unary<T<A>, Unary<A, T<boolean>>>
Creates a check function starting from a a message or a mappable functor.
Example
import { Assert, Num } from 'tiinvo'
const check1 = Assert.makeResult(Num.isEven, x => `number ${x} is not even`)
check0(10) // true
check0(11) // Error("number is not even")
check1(10) // true
check1(11) // Error("number 11 is not even")
Since
4.0.0
| Name | Description |
|---|---|
A |
the type passed to the predicate and to the mappable functor (if any) |
| Name | Type | Description |
|---|---|---|
p |
string | Mappable<A, string> |
the error message or the mappable functor |
Unary<T<A>, Unary<A, T<boolean>>>
the asserting unary function which returns
Result.Ok<true> if a is trueResult.Err otherwise