Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions exercises/practice/list-ops/.meta/additional_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"input": {
"list": ["e", "x", "e", "r", "c", "i", "s", "m"],
"initial": "!",
"function": "(x, y) -> x + y"
"function": "(acc, el) -> el + acc"
},
"expected": "exercism!"
},
Expand All @@ -19,4 +19,4 @@
"expected": [1, "cat", 4.0, "xyz"]
}
]
}
}
1 change: 1 addition & 0 deletions exercises/practice/list-ops/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"Dog",
"dvermd",
"gabriel376",
"IsaacG",
"N-Parsons",
"pheanex",
"rootulp",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/list-ops/.meta/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def foldr(function, list, initial):
if len(list) == 0:
return initial
else:
return function(list[0], foldr(function, list[1:], initial))
return function(foldr(function, list[1:], initial), list[0])


def reverse(list):
Expand Down
1 change: 0 additions & 1 deletion exercises/practice/list-ops/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% macro lambdify(function) -%}
{% set function = function.replace("(", "", 1).replace(")", "", 1).replace(" ->", ":") %}
{% set function = function.replace("modulo", "%") %}
{% set function = function.replace("/", "//") %}
lambda {{function}}
{%- endmacro %}

Expand Down
2 changes: 0 additions & 2 deletions exercises/practice/list-ops/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ reimplements = "e56df3eb-9405-416a-b13a-aabb4c3b5194"
[d7fcad99-e88e-40e1-a539-4c519681f390]
description = "folds (reduces) the given list from the left with a function -> direction dependent function applied to non-empty list"
reimplements = "d2cf5644-aee1-4dfc-9b88-06896676fe27"
include = false

[aeb576b9-118e-4a57-a451-db49fac20fdc]
description = "folds (reduces) the given list from the right with a function -> empty list"
Expand All @@ -96,7 +95,6 @@ reimplements = "c4b64e58-313e-4c47-9c68-7764964efb8e"
[8066003b-f2ff-437e-9103-66e6df474844]
description = "folds (reduces) the given list from the right with a function -> direction dependent function applied to non-empty list"
reimplements = "be396a53-c074-4db3-8dd6-f7ed003cce7c"
include = false

[94231515-050e-4841-943d-d4488ab4ee30]
description = "reverse the elements of the list -> empty list"
Expand Down
10 changes: 9 additions & 1 deletion exercises/practice/list-ops/list_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ def test_foldl_empty_list(self):
def test_foldl_direction_independent_function_applied_to_non_empty_list(self):
self.assertEqual(foldl(lambda acc, el: el + acc, [1, 2, 3, 4], 5), 15)

def test_foldl_direction_dependent_function_applied_to_non_empty_list(self):
self.assertEqual(foldl(lambda acc, el: el / acc, [1, 2, 3, 4], 24), 64)

def test_foldr_empty_list(self):
self.assertEqual(foldr(lambda acc, el: el * acc, [], 2), 2)

def test_foldr_direction_independent_function_applied_to_non_empty_list(self):
self.assertEqual(foldr(lambda acc, el: el + acc, [1, 2, 3, 4], 5), 15)

def test_foldr_direction_dependent_function_applied_to_non_empty_list(self):
self.assertEqual(foldr(lambda acc, el: el / acc, [1, 2, 3, 4], 24), 9)

def test_reverse_empty_list(self):
self.assertEqual(reverse([]), [])

Expand All @@ -84,7 +90,9 @@ def test_reverse_list_of_lists_is_not_flattened(self):

def test_foldr_foldr_add_string(self):
self.assertEqual(
foldr(lambda x, y: x + y, ["e", "x", "e", "r", "c", "i", "s", "m"], "!"),
foldr(
lambda acc, el: el + acc, ["e", "x", "e", "r", "c", "i", "s", "m"], "!"
),
"exercism!",
)

Expand Down