我正在尝试运行以下示例。它使用sanctuary.js。
const {create, env} = require('sanctuary');
const S = create({checkTypes: false, env: env});
const test = require('tape');
class Person {
constructor(name){
this.name = S.maybeToEither('')(S.toMaybe(name));
}
};
const capitalize = (string) => string[0].toUpperCase() + string.substring(1);
const tigerify = (string) => `${string}, the tiger`;
const display = (string) => string.toString();
const tigerize = S.compose(capitalize)(tigerify);
test("Displaying a person", (assert) => {
const personOne = new Person("tony");
const actual = S.either(S.identity)(tigerize)(personOne.name);
const expected = 'Tony, the tiger';
assert.equal(actual, expected);
assert.end();
});
test("Displaying an anonymous person", (assert) => {
const personTwo = new Person(null);
const actual = S.either(S.identity)(tigerize)(personTwo.name);
const expected = '';
assert.equal(actual, expected);
assert.end();
});在第28行字符48上发生以下错误:
TypeError: (intermediate value)(intermediate value)(intermediate value) is not a function这是由以下行中的personTwo.name造成的:
const actual = S.either(S.identity)(tigerize)(personTwo.name);我可以看出personTwo.name是Left。为什么这会触发错误而不是返回空字符串?
发布于 2018-06-09 09:54:55
看起来我部分地使用了过时的api。
通过将S.identity更改为S.I,该示例有效。
https://stackoverflow.com/questions/50772411
复制相似问题