UNPKG

pure-parse

Version:

Strongly typed validation library that decouples type aliases from validation logic

2 lines (1 loc) 407 B
import{failure as a,propagateFailure as o,success as s}from"./ParseResult.js";const g=t=>r=>{if(!Array.isArray(r))return a("Expected array");if(r.length<t.length)return a(`the data has ${r.length} elements but ${t.length} are required`);const n=[];for(let e=0;e<t.length;e++){const l=t[e],i=r[e],u=l(i);if(u.tag==="failure")return o(u,{tag:"array",index:e});n.push(u.value)}return s(n)};export{g as tuple};