class SyntaxTree::Lambda

def format(q)

def format(q)
  params = self.params
  q.text("->")
  q.group do
    if params.is_a?(Paren)
      q.format(params) unless params.contents.empty?
    elsif params.empty? && params.comments.any?
      q.format(params)
    elsif !params.empty?
      q.group do
        q.text("(")
        q.format(params)
        q.text(")")
      end
    end
    q.text(" ")
    q
      .if_break do
        force_parens =
          q.parents.any? do |node|
            node.is_a?(Command) || node.is_a?(CommandCall)
          end
        if force_parens
          q.text("{")
          unless statements.empty?
            q.indent do
              q.breakable_space
              q.format(statements)
            end
            q.breakable_space
          end
          q.text("}")
        else
          q.text("do")
          unless statements.empty?
            q.indent do
              q.breakable_space
              q.format(statements)
            end
          end
          q.breakable_space
          q.text("end")
        end
      end
      .if_flat do
        q.text("{")
        unless statements.empty?
          q.text(" ")
          q.format(statements)
          q.text(" ")
        end
        q.text("}")
      end
  end
end