mirror of
https://github.com/rjNemo/functional-programming-jargon
synced 2026-06-06 02:26:43 +00:00
Merge pull request #191 from MiroslavPetrik/patch-1
fix partial function `sum` example
This commit is contained in:
commit
aea00f1338
1 changed files with 2 additions and 2 deletions
|
|
@ -926,7 +926,7 @@ A partial function is a [function](#function) which is not defined for all argum
|
||||||
// sum :: [Number] -> Number
|
// sum :: [Number] -> Number
|
||||||
const sum = arr => arr.reduce((a, b) => a + b)
|
const sum = arr => arr.reduce((a, b) => a + b)
|
||||||
sum([1, 2, 3]) // 6
|
sum([1, 2, 3]) // 6
|
||||||
sqrt([]) // TypeError: Reduce of empty array with no initial value
|
sum([]) // TypeError: Reduce of empty array with no initial value
|
||||||
|
|
||||||
// example 2: get the first item in list
|
// example 2: get the first item in list
|
||||||
// first :: [A] -> A
|
// first :: [A] -> A
|
||||||
|
|
@ -957,7 +957,7 @@ Fortunately a partial function can be converted to a regular (or total) one. We
|
||||||
// sum :: [Number] -> Number
|
// sum :: [Number] -> Number
|
||||||
const sum = arr => arr.reduce((a, b) => a + b, 0)
|
const sum = arr => arr.reduce((a, b) => a + b, 0)
|
||||||
sum([1, 2, 3]) // 6
|
sum([1, 2, 3]) // 6
|
||||||
sqrt([]) // 0
|
sum([]) // 0
|
||||||
|
|
||||||
// example 2: get the first item in list
|
// example 2: get the first item in list
|
||||||
// change result to Option
|
// change result to Option
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue