case'string':returntypeof(value)==='string'?Either.of(valueasany):Either.failure(`expected a string, got ${fancyTypeOf(value)}`);
case'boolean':returntypeof(value)==='boolean'?Either.of(valueasany):Either.failure(`expected a boolean, got ${fancyTypeOf(value)}`);
case'any':returnEither.of(value);
case'nat':returntypeof(value)!=='number'?Either.failure('not a number'):(value|0)===value&&value>=0?Either.of(valueasany):Either.failure('not a natural number');
case'int':returntypeof(value)!=='number'?Either.failure('not a number'):(value|0)===value?Either.of(valueasany):Either.failure('not an integer')
case'float':returntypeof(value)!=='number'?Either.failure('not a number'):Either.of(valueasany);
}
}
}
...
...
@@ -325,27 +237,16 @@ export class OneOfDecoder<A> extends DecoderBase<A> {
case'string':returntypeof(value)==='string'?Either.of(valueasany):Either.failure(projectProblem(`expected a string, got ${fancyTypeOf(value)}`));
case'boolean':returntypeof(value)==='boolean'?Either.of(valueasany):Either.failure(projectProblem(`expected a boolean, got ${fancyTypeOf(value)}`));
case'any':returnEither.of(valueasA);
case'nat':returntypeof(value)!=='number'?Either.failure(projectProblem('not a number')):(value|0)===value&&value>=0?Either.of(valueasany):Either.failure(projectProblem('not a natural number'));
case'int':returntypeof(value)!=='number'?Either.failure(projectProblem('not a number')):(value|0)===value?Either.of(valueasany):Either.failure(projectProblem('not an integer'))
case'float':returntypeof(value)!=='number'?Either.failure(projectProblem('not a number')):Either.of(valueasany);
}
returnabsurd(decoder.primitive);
}
if(decoderinstanceofPureDecoder){
returndecoder.value.mapLeft(projectProblem);
}
if(decoderinstanceofOneOfDecoder){
for(constdecoderofthis.alternatives){
constethr=decoder.validate(value);
switch(ethr.tag){
case'Left':break;
case'Right':returnethr;
}
}
returnEither.failure(projectProblem('none of decoders succeded'));