Skip to content

Bool

Functions for working with boolean values.

FunctionSignatureDescription
Bool.guardboolean, T, () -> T -> TContinue if true, bail with fallback if false (for use)

Bool.guard combines with use to give linear early-return flow. If the condition is false, the fallback value is returned. If true, execution continues:

type AdminPageProps { auth: Auth }
export fn AdminPage(props: AdminPageProps) -> JSX.Element {
use <- Bool.guard(props.auth.isAdmin, <Forbidden />)
use <- Bool.guard(props.auth.isVerified, <VerifyPrompt />)
<AdminPanel />
}

This replaces the TypeScript pattern of nested if checks with early returns:

// TypeScript
function AdminPage({ auth }) {
if (!auth.isAdmin) return <Forbidden />;
if (!auth.isVerified) return <VerifyPrompt />;
return <AdminPanel />;
}

Bool.guard is just a stdlib function — no new syntax. Inspired by Gleam’s bool.guard.

See the Callback Flattening & Guards guide for the full pattern including Option.guard and Result.guard.