DEV Community

Discussion on: Either: fp-ts

Collapse
 
josuevalrob profile image
Josue Valenica

Just for the record i was trying to implement it and got:

TypeError: Method RegExp.prototype.test called on incompatible receiver undefined

the solution:

const regexLetters = /[a-zA-z]/;
const test = (x:string) => regexLetters.test(x);
// (name: string) => Either<string, string>
const validateName = E.fromPredicate(
    test,
    (name) => `"${name}" is not a valid name!`
);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
waynevanson profile image
Wayne Van Son

Looks like it's not inferring the input type from the signature. I'll update this, thank you!