1"use strict";(globalThis.webpackChunkdocs=globalThis.webpackChunkdocs||[]).push([[2329],{73905(e,n,t){t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>i,default:()=>l,frontMatter:()=>a,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"language/data_types/function_types","title":"Function types","description":"Define and use function types for higher\u2011order functions in Noir, including syntax, examples, and notes on closures.","source":"@site/versioned_docs/version-v1.0.0-rc.2/language/data_types/function_types.md","sourceDirName":"language/data_types","slug":"/language/data_types/function_types","permalink":"/docs/language/data_types/function_types","draft":false,"unlisted":false,"editUrl":"https://github.com/noir-lang/noir/edit/master/docs/versioned_docs/version-v1.0.0-rc.2/language/data_types/function_types.md","tags":[],"version":"v1.0.0-rc.2","frontMatter":{"title":"Function types","description":"Define and use function types for higher\u2011order functions in Noir, including syntax, examples, and notes on closures."},"sidebar":"sidebar","previous":{"title":"References","permalink":"/docs/language/data_types/references"},"next":{"title":"Type Casting and Coercions","permalink":"/docs/language/data_types/coercions"}}');var r=t(74848),o=t(28453);const a={title:"Function types",description:"Define and use function types for higher\u2011order functions in Noir, including syntax, examples, and notes on closures."},i=void 0,c={},u=[];function d(e){const n={a:"a",code:"code",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"Noir supports higher-order functions. The syntax for a function type is as follows:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-rust",children:"fn(arg1_type, arg2_type, ...) -> return_type\n"})}),"\n",(0,r.jsx)(n.p,{children:"Example:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-rust",children:"fn assert_returns_100(f: fn() -> Field) { // f takes no args and returns a Field\n assert(f() == 100);\n}\n\nfn main() {\n assert_returns_100(|| 100); // ok\n assert_returns_100(|| 150); // fails\n}\n"})}),"\n",(0,r.jsxs)(n.p,{children:["A function type also has an optional capture environment - this is necessary to support closures.\nSee ",(0,r.jsx)(n.a,{href:"/docs/language/lambdas",children:"Lambdas"})," for more details."]})]})}function l(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},28453(e,n,t){t.d(n,{R:()=>a,x:()=>i});var s=t(96540);const r={},o=s.createContext(r);function a(e){const n=s.useContext(o);return s.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(o.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.