我应该将什么值传递给 Sanctuary.either()?

What value should I pass to Sanctuary.either()?

我正在尝试运行下面的例子。它使用 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。为什么这会触发错误而不是返回空字符串?

看来我部分使用了过时的 api。

通过将 S.identity 更改为 S.I 该示例有效。