mirror of
https://github.com/rjNemo/functional-programming-jargon
synced 2026-06-06 02:26:43 +00:00
fix contract function type
This commit is contained in:
parent
b593d7c1ca
commit
62bc8a59f5
1 changed files with 2 additions and 2 deletions
|
|
@ -346,13 +346,13 @@ A contract specifies the obligations and guarantees of the behavior from a funct
|
||||||
// Define our contract : int -> boolean
|
// 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