From 71a8a5996c1eed0ffeea1283ddea5aa63686ce7c Mon Sep 17 00:00:00 2001 From: Sebastian Porto Date: Fri, 9 Apr 2021 16:52:49 +1000 Subject: Flip order of args passed to fn in map_reduce. Item first and memo second. --- src/gleam/list.gleam | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 6d9c709..e911b80 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -262,18 +262,18 @@ pub fn map(list: List(a), with fun: fn(a) -> b) -> List(b) { pub fn map_reduce( over list: List(a), from memo: memo, - with fun: fn(memo, a) -> tuple(memo, b), -) -> tuple(memo, List(b)) { + with fun: fn(a, memo) -> tuple(b, memo), +) -> tuple(List(b), memo) { fold( over: list, - from: tuple(memo, []), + from: tuple([], memo), with: fn(item, acc) { - let tuple(current_memo, items) = acc - let tuple(next_memo, next_item) = fun(current_memo, item) - tuple(next_memo, [next_item, ..items]) + let tuple(items, current_memo) = acc + let tuple(next_item, next_memo) = fun(item, current_memo) + tuple([next_item, ..items], next_memo) }, ) - |> pair.map_second(reverse) + |> pair.map_first(reverse) } fn do_index_map( -- cgit v1.2.3