From 2d86bf5aa32571153569434631a98aa72e49a86a Mon Sep 17 00:00:00 2001 From: MystPi <86574651+MystPi@users.noreply.github.com> Date: Fri, 26 Apr 2024 02:56:06 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Tail-call=20optimize=20fun?= =?UTF-8?q?ction=20captures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/glam/doc.gleam | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/glam/doc.gleam b/src/glam/doc.gleam index 2fb9569..5829a8e 100644 --- a/src/glam/doc.gleam +++ b/src/glam/doc.gleam @@ -594,14 +594,17 @@ fn do_to_string( |> do_to_string(max_width, indent, rest) } - ForceBreak(doc) -> - [#(indent, ForceBroken, doc), ..rest] - |> do_to_string(acc, max_width, current_width, _) + ForceBreak(doc) -> { + let docs = [#(indent, ForceBroken, doc), ..rest] + do_to_string(acc, max_width, current_width, docs) + } - Concat(docs) -> - list.map(docs, fn(doc) { #(indent, mode, doc) }) - |> list.append(rest) - |> do_to_string(acc, max_width, current_width, _) + Concat(docs) -> { + let docs = + list.map(docs, fn(doc) { #(indent, mode, doc) }) + |> list.append(rest) + do_to_string(acc, max_width, current_width, docs) + } Group(doc) -> { let fits = fits([#(indent, Unbroken, doc)], max_width, current_width) @@ -609,13 +612,14 @@ fn do_to_string( True -> Unbroken False -> Broken } - [#(indent, new_mode, doc), ..rest] - |> do_to_string(acc, max_width, current_width, _) + let docs = [#(indent, new_mode, doc), ..rest] + do_to_string(acc, max_width, current_width, docs) } - Nest(doc, i) -> - [#(indent + i, mode, doc), ..rest] - |> do_to_string(acc, max_width, current_width, _) + Nest(doc, i) -> { + let docs = [#(indent + i, mode, doc), ..rest] + do_to_string(acc, max_width, current_width, docs) + } Text(text: text, length: length) -> do_to_string(acc <> text, max_width, current_width + length, rest)