fix partial function sum example

This commit is contained in:
Miroslav Petrik 2018-12-25 13:19:53 +01:00 committed by GitHub
parent ca37a0e6d4
commit 7f6f412552
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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