I'm attempting to validate an operation of applying a command to an array representing svg path data using fp-ts.
type CommandValidation = (commands: CommandArray, nextCommand: Command) => option.Option<string>;
const newCommandValidations: Array<CommandValidation> = [
validateFirstCommandIsMove,
validateSymmetricCommandFollowsBezier,
validateNoMoveAfterMove,
];
export const safelyPushCommand = (command: Command) => either.map((commands: CommandArray) => {
// the errors don't overlap yet but in future errors may co-exist
const validationErrors = fpFunction.pipe(newCommandValidations,
fpArray.map((validation) => validation(commands, command)),
fpArray.filter(option.isSome),
fpArray.map(option.fold(() => undefined, (some) => some)));
if (validationErrors.length > 0) {
return either.left(validationErrors);
}
return either.right(pushCommands([command])(commands));
});
Unfortunately the validationErrors is still regarded as a list of items which could have a none in them.
How can I get a array of strings (typed as such) representing any validation errors for this operation.
Should I be using an "apply" function to put the parameters into the validation functions?
How can I get an apply function for the validators?
Is there a better way to do the fold operation when the second function is just the identity function?
EDIT: I had this question answered in this video https://youtu.be/1LCqHnaJJtY?t=2470 : option.fold(() => undefined, (some) => some) === option.getOrElse(() => undefined) === option.toUndefined
Lots of questions from someone lost in the jungle of fp-ts, hope you can provide some insight to help my project become useful. The example code is contained in a branch I cut here: https://github.com/justin-hackin/fp-ts-svg-path-d/tree/validators