← Lua Academy

Typed Lua · 37 / 69

Keep callback contracts

YOUR TASK

Make this happen

3 steps
  1. A callback annotation describes both input and output. Return a function that formats a number as text.

  2. Read the cases in lesson.test.lua, then choose Check solution to see what needs to change.

  3. Update subject.lua until every test passes. Keep the supplied tests unchanged.

Read the starter and tests

subject.lua

exports.formatter = function(): (number) -> string
  return function(n: number): string
    return n
  end
end

lesson.test.lua

local t = require("test")
local subject = require("cococo.subject")
t.it("formats number", function()
  local s = subject.load()
  t.expect(s.formatter()(12)):eq("12")
end)