-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hs.fnutils.reduce takes an optional initial value
This is in line with the reduce function in other languages like JavaScript, Python, and Ruby.
- Loading branch information
Showing
2 changed files
with
24 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function test_reduce() | ||
local reduce = hs.fnutils.reduce | ||
|
||
assert(reduce({}, function(x, y) return x + y end) == nil) | ||
assert(reduce({}, function(x, y) return x + y end, 10) == 10) | ||
assert(reduce({1}, function(x, y) return x + y end) == 1) | ||
assert(reduce({1}, function(x, y) return x + y end, 10) == 11) | ||
assert(reduce({1, 2}, function(x, y) return x + y end) == 3) | ||
assert(reduce({1, 2}, function(x, y) return x + y end, 10) == 13) | ||
end |