[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    [ANN] Typecheck 1.0 - Magic coroutine mess
From:       "Soni L." <fakedme () gmail ! com>
Date:       2017-02-20 2:48:39
Message-ID: 8f403420-aa46-0923-0181-ebae39b9b170 () gmail ! com
[Download RAW message or body]

Typecheck is a Lua module for checking types. It uses annotation-style 
checks and depends on APow[1].

Repo: https://bitbucket.org/TeamSoni/typecheck

It was inspired by `nil` being a separate type in Lua.

Features:

- Coroutine tricks.
- Annotation-style API.
- Return-style typechecks.
- Non-nil by default.

Examples:

- - -
local tc = require "typecheck"

-- Simple checks, error() on invalid type
-- AKA "unchecked exception" style

local function mustbetable(t)
   t = tc.uncheck "table" ^ t
   return t.n or #t
end

local function tableornil(t)
   t = tc.uncheck "table" "nil" ^ t
   return t and (t.n or #t) or 0
end

-- "Checked exception" style, returns `nil, errmsg` on invalid type
-- (note the use of tc.checked)

local mustbeopenfile = tc.checked ^ function(f)
   f = tc.check(io.type, "file") ^ f
   return f:seek()
end
- - -

[1]: https://bitbucket.org/TeamSoni/apow

-- 
Disclaimer: these emails may be made public at any given time, with or without \
reason. If you don't agree with this, DO NOT REPLY.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic