[{"data":1,"prerenderedAt":630},["ShallowReactive",2],{"content-\u002Freference\u002F0.4.x\u002Fstdlib":3,"use-cases-nav":623},{"id":4,"title":5,"author":6,"body":7,"date":6,"description":615,"extension":616,"meta":617,"navigation":58,"order":55,"path":618,"seo":619,"stem":620,"version":621,"__hash__":622},"content\u002Freference\u002F0.4.x\u002Fstdlib.md","Standard Library",null,{"type":8,"value":9,"toc":608},"minimark",[10,31,78,84,96,101,104,238,249,253,268,349,378,393,397,408,411,439,460,464,467,496,506,510,521,585,604],[11,12,13,14,18,19,18,22,25,26,30],"p",{},"Since 0.4, ",[15,16,17],"code",{},"String",", ",[15,20,21],{},"Integer",[15,23,24],{},"Date"," and the rest are ",[27,28,29],"strong",{},"not builtin",". They\nare ordinary definitions living in a standard library, and a schema brings\nthem into scope with an import:",[32,33,38],"pre",{"className":34,"code":35,"language":36,"meta":37,"style":37},"language-finitio shiki shiki-themes github-light github-dark","@import finitio\u002Fdata\n\n{ name: String, age: Integer }\n","finitio","",[15,39,40,53,60],{"__ignoreMap":37},[41,42,45,49],"span",{"class":43,"line":44},"line",1,[41,46,48],{"class":47},"szBVR","@import",[41,50,52],{"class":51},"sZZnC"," finitio\u002Fdata\n",[41,54,56],{"class":43,"line":55},2,[41,57,59],{"emptyLinePlaceholder":58},true,"\n",[41,61,63,67,70,73,75],{"class":43,"line":62},3,[41,64,66],{"class":65},"sVt8B","{ name: ",[41,68,17],{"class":69},"sj4cs",[41,71,72],{"class":65},", age: ",[41,74,21],{"class":69},[41,76,77],{"class":65}," }\n",[11,79,80,81,83],{},"Without that first line, ",[15,82,17],{}," is simply an unknown type and the schema\nfails to compile. This is the single biggest change for a reader coming from\n0.3.",[11,85,86,87,92,93,95],{},"The library is written in Finitio itself, on top of\n",[88,89,91],"a",{"href":90},"\u002Freference\u002F0.4.x\u002Ftype-system#builtin-types","builtin types"," — ",[15,94,21],{}," is\nlittle more than a named alias for a host abstraction, which is precisely how\nFinitio stays host-independent at the schema level.",[97,98,100],"h2",{"id":99},"the-portable-core","The portable core",[11,102,103],{},"These behave the same in both implementations and are what you should reach\nfor:",[105,106,107,123],"table",{},[108,109,110],"thead",{},[111,112,113,117,120],"tr",{},[114,115,116],"th",{},"Type",[114,118,119],{},"Captures",[114,121,122],{},"Exchange representation",[124,125,126,142,161,175,189,210,224],"tbody",{},[111,127,128,134,137],{},[129,130,131],"td",{},[15,132,133],{},"Nil",[129,135,136],{},"the null value",[129,138,139],{},[15,140,141],{},"null",[111,143,144,149,152],{},[129,145,146],{},[15,147,148],{},"Boolean",[129,150,151],{},"true and false",[129,153,154,157,158],{},[15,155,156],{},"true"," \u002F ",[15,159,160],{},"false",[111,162,163,168,171],{},[129,164,165],{},[15,166,167],{},"True",[129,169,170],{},"only true",[129,172,173],{},[15,174,156],{},[111,176,177,182,185],{},[129,178,179],{},[15,180,181],{},"False",[129,183,184],{},"only false",[129,186,187],{},[15,188,160],{},[111,190,191,196,199],{},[129,192,193],{},[15,194,195],{},"Numeric",[129,197,198],{},"any number",[129,200,201,18,204,18,207],{},[15,202,203],{},"12",[15,205,206],{},"12.0",[15,208,209],{},"12.5",[111,211,212,216,219],{},[129,213,214],{},[15,215,17],{},[129,217,218],{},"any string",[129,220,221],{},[15,222,223],{},"\"finitio\"",[111,225,226,230,233],{},[129,227,228],{},[15,229,24],{},[129,231,232],{},"a calendar date",[129,234,235],{},[15,236,237],{},"\"2014-07-17\"",[11,239,240,241,244,245,248],{},"The Any type is written ",[15,242,243],{},"."," rather than named. Both implementations\nunderstand the dot; only finitio.js also defines ",[15,246,247],{},"Any"," as a name.",[97,250,252],{"id":251},"numbers-need-care","Numbers need care",[11,254,255,257,258,260,261,264,265,267],{},[15,256,195],{}," behaves identically everywhere. ",[15,259,21],{}," and ",[15,262,263],{},"Real"," do not,\nbecause the two host languages disagree about what ",[15,266,206],{}," is.",[105,269,270,295],{},[108,271,272],{},[111,273,274,277,282,287,291],{},[114,275,276],{},"document",[114,278,279,281],{},[15,280,21],{}," in Ruby",[114,283,284,286],{},[15,285,21],{}," in JS",[114,288,289,281],{},[15,290,263],{},[114,292,293,286],{},[15,294,263],{},[124,296,297,313,335],{},[111,298,299,303,306,308,311],{},[129,300,301],{},[15,302,203],{},[129,304,305],{},"accepted",[129,307,305],{},[129,309,310],{},"rejected",[129,312,310],{},[111,314,315,319,323,327,331],{},[129,316,317],{},[15,318,206],{},[129,320,321],{},[27,322,310],{},[129,324,325],{},[27,326,305],{},[129,328,329],{},[27,330,305],{},[129,332,333],{},[27,334,310],{},[111,336,337,341,343,345,347],{},[129,338,339],{},[15,340,209],{},[129,342,310],{},[129,344,310],{},[129,346,305],{},[129,348,305],{},[11,350,351,352,354,355,358,359,361,362,364,365,260,367,369,370,372,373,375,376,243],{},"Ruby parses ",[15,353,206],{}," from JSON into a ",[15,356,357],{},"Float",", so it is a ",[15,360,263],{}," and not an\n",[15,363,21],{},". JavaScript has a single number type in which ",[15,366,206],{},[15,368,203],{}," are\nthe same value, so finitio.js decides by looking for a fractional part: ",[15,371,206],{},"\nis an ",[15,374,21],{}," and is not a ",[15,377,263],{},[11,379,380,381,383,384,386,387,389,390,392],{},"In practice: ",[15,382,195],{}," is always safe; ",[15,385,21],{}," agrees on values written\nwithout a decimal point; ",[15,388,263],{}," agrees on values that genuinely have a\nfractional part. A schema that must run under both bindings should avoid\ndepending on how ",[15,391,206],{}," is classified.",[97,394,396],{"id":395},"dates-and-times","Dates and times",[11,398,399,401,402,404,405,407],{},[15,400,24],{}," accepts an ISO 8601 date string in both, and dresses it into the host's\ndate class — a ",[15,403,24],{}," in Ruby, a ",[15,406,24],{}," in JavaScript.",[11,409,410],{},"Beyond that the two libraries diverge:",[412,413,415],"impl-note",{"impl":414},"finitio.js",[11,416,417,260,419,422,423,426,427,431,432,434,435,438],{},[15,418,24],{},[15,420,421],{},"Time"," also carry a ",[15,424,425],{},"\u003Cmilliseconds>"," contract, so a ",[428,429,430],"em",{},"number"," is\naccepted and dressed as an epoch timestamp. finitio-rb's ",[15,433,24],{}," has only the\n",[15,436,437],{},"\u003Ciso8601>"," contract and rejects numbers.",[412,440,442],{"impl":441},"finitio-rb",[11,443,444,447,448,450,451,453,454,456,457,459],{},[15,445,446],{},"DateTime"," exists as a separate type, and ",[15,449,421],{}," expects a time rather than a\ndate — ",[15,452,237],{}," is rejected by finitio-rb's ",[15,455,421],{}," and accepted by\nfinitio.js's. Prefer ",[15,458,24],{}," for calendar dates in portable schemas.",[97,461,463],{"id":462},"implementation-specific-names","Implementation-specific names",[11,465,466],{},"Some names exist in only one library. They are aliases for host abstractions,\nso they cannot be portable by nature:",[412,468,469],{"impl":441},[11,470,471,18,474,18,477,18,480,260,482,484,485,18,487,18,489,18,491,260,493,495],{},[15,472,473],{},"NilClass",[15,475,476],{},"TrueClass",[15,478,479],{},"FalseClass",[15,481,357],{},[15,483,446],{}," name Ruby\nclasses directly. Use ",[15,486,133],{},[15,488,167],{},[15,490,181],{},[15,492,263],{},[15,494,24],{}," instead when\nthe schema has to run elsewhere.",[412,497,498],{"impl":414},[11,499,500,502,503,505],{},[15,501,247],{}," is defined as a name. The dot notation ",[15,504,243],{}," means the same thing and\nworks in both.",[97,507,509],{"id":508},"reading-the-library","Reading the library",[11,511,512,513,516,517,520],{},"The library is a normal Finitio file and worth a look — it is the clearest\nexample of the language describing itself. In finitio-rb it lives at\n",[15,514,515],{},"lib\u002Ffinitio\u002Fstdlib\u002Ffinitio\u002Fdata.fio","; in finitio.js at\n",[15,518,519],{},"src\u002Ffinitio\u002Fstdlib\u002Fdata.fio",". A definition looks like this:",[32,522,524],{"className":34,"code":523,"language":36,"meta":37,"style":37},"Date = .Date \u003Ciso8601> .String \\( s | Date.iso8601(s) )\n                               \\( d | d.iso8601       )\n",[15,525,526,570],{"__ignoreMap":37},[41,527,528,531,534,537,539,542,546,549,551,554,557,561,564,567],{"class":43,"line":44},[41,529,24],{"class":530},"sScJk",[41,532,533],{"class":47}," =",[41,535,536],{"class":65}," .",[41,538,24],{"class":69},[41,540,541],{"class":65}," \u003C",[41,543,545],{"class":544},"s9eBZ","iso8601",[41,547,548],{"class":65},"> .",[41,550,17],{"class":69},[41,552,553],{"class":47}," \\",[41,555,556],{"class":65},"( ",[41,558,560],{"class":559},"s4XuR","s",[41,562,563],{"class":47}," |",[41,565,566],{"class":69}," Date",[41,568,569],{"class":65},".iso8601(s) )\n",[41,571,572,575,577,580,582],{"class":43,"line":55},[41,573,574],{"class":47},"                               \\",[41,576,556],{"class":65},[41,578,579],{"class":559},"d",[41,581,563],{"class":47},[41,583,584],{"class":65}," d.iso8601       )\n",[11,586,587,588,592,593,595,596,598,599,603],{},"That is an ",[88,589,591],{"href":590},"\u002Freference\u002F0.4.x\u002Ftype-system#abstract-data-types","abstract data type","\nbound to the host's ",[15,594,24],{}," class through one named contract, ",[15,597,545],{},", with\nits dress and undress functions. See\n",[88,600,602],{"href":601},"\u002Freference\u002F0.4.x\u002Finformation-contracts","information contracts"," for what those\ntwo functions mean.",[605,606,607],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s9eBZ, html code.shiki .s9eBZ{--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}",{"title":37,"searchDepth":62,"depth":62,"links":609},[610,611,612,613,614],{"id":99,"depth":55,"text":100},{"id":251,"depth":55,"text":252},{"id":395,"depth":55,"text":396},{"id":462,"depth":55,"text":463},{"id":508,"depth":55,"text":509},"Finitio 0.4 standard library: the types provided by finitio\u002Fdata.","md",{},"\u002Freference\u002F0.4.x\u002Fstdlib",{"title":5,"description":615},"reference\u002F0.4.x\u002Fstdlib","0.4.x","eQogkIdaJDeqIVm9fJJ5ijiNt_D3JvTPdwLW4HW9SfA",[624,627],{"path":625,"title":626},"\u002Fuse-cases","Use cases",{"path":628,"title":629},"\u002Fuse-cases\u002Fcleaning-csv-files","Cleaning .csv files",1786026251330]