diff --git a/src/dllist.gleam b/src/dllist.gleam index 83554e4..71be07b 100644 --- a/src/dllist.gleam +++ b/src/dllist.gleam @@ -237,18 +237,18 @@ pub fn to_list(list: DLList(a)) -> List(a) { True -> [] False -> { let assert Ok(a) = get(list) - [a, ..to_list_loop(list.current, do_move_right(list))] + [a, ..to_list_loop(do_move_right(list), list.current)] } } } -fn to_list_loop(ref: Int, list: Result(DLList(a), Nil)) -> List(a) { +fn to_list_loop(list: Result(DLList(a), Nil), start_ref: Int) -> List(a) { case list { Error(_) -> [] - Ok(DLList(_, current, _)) if current == ref -> [] + Ok(DLList(_, current, _)) if current == start_ref -> [] Ok(list) -> { let assert Ok(a) = get(list) - [a, ..to_list_loop(ref, do_move_right(list))] + [a, ..to_list_loop(do_move_right(list), start_ref)] } } }