首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我应该将什么值传递给Sanctuary.either()?

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

Stack Overflow用户
提问于 2018-06-09 08:36:38
回答 1查看 273关注 0票数 0

我正在尝试运行以下示例。它使用sanctuary.js。

代码语言:javascript
复制
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上发生以下错误:

代码语言:javascript
复制
TypeError: (intermediate value)(intermediate value)(intermediate value) is not a function

这是由以下行中的personTwo.name造成的:

代码语言:javascript
复制
const actual = S.either(S.identity)(tigerize)(personTwo.name);

我可以看出personTwo.name是Left。为什么这会触发错误而不是返回空字符串?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-09 09:54:55

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50772411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档