mirror of
https://github.com/rjNemo/functional-programming-jargon
synced 2026-06-06 02:26:43 +00:00
Merge pull request #193 from emarukyan/master
fix contract function type in comments
This commit is contained in:
commit
d2529c2e33
1 changed files with 3 additions and 3 deletions
|
|
@ -343,16 +343,16 @@ const predicate = (a) => a > 2
|
||||||
A contract specifies the obligations and guarantees of the behavior from a function or expression at runtime. This acts as a set of rules that are expected from the input and output of a function or expression, and errors are generally reported whenever a contract is violated.
|
A contract specifies the obligations and guarantees of the behavior from a function or expression at runtime. This acts as a set of rules that are expected from the input and output of a function or expression, and errors are generally reported whenever a contract is violated.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Define our contract : int -> int
|
// Define our contract : int -> boolean
|
||||||
const contract = (input) => {
|
const contract = (input) => {
|
||||||
if (typeof input === 'number') return true
|
if (typeof input === 'number') return true
|
||||||
throw new Error('Contract violated: expected int -> int')
|
throw new Error('Contract violated: expected int -> boolean')
|
||||||
}
|
}
|
||||||
|
|
||||||
const addOne = (num) => contract(num) && num + 1
|
const addOne = (num) => contract(num) && num + 1
|
||||||
|
|
||||||
addOne(2) // 3
|
addOne(2) // 3
|
||||||
addOne('some string') // Contract violated: expected int -> int
|
addOne('some string') // Contract violated: expected int -> boolean
|
||||||
```
|
```
|
||||||
|
|
||||||
## Category
|
## Category
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue