【发布时间】:2021-08-07 12:39:37
【问题描述】:
我有以下代码
export const getPostData = (id: string) =>
pipe(
getFullPathFileNameForPosts(`${id}.md`), // IO<string>
chain(getFileContents), // IO<string>
chain(getMatter), // IO<matter.GrayMatterFile<string>>
map(R.pick(['data'])),
bind('id', () => () => id)
);
以上函数getPostData()retun
IO<{
data: {[key: string]: any};
id: string;
}>
现在我必须在返回的结果中添加一些文件,比如说content,结果看起来像
IO<{
data: {[key: string]: any};
id: string;
content: string;
}>
我写了一个新函数getContent = (matter: matter.GrayMatterFile<string>) => {...},现在如何将这个函数添加到组合函数getPostData中?
我想问的主要问题是如何将值分成不同的函数在组合函数中进行处理。
因为chain(getFileContents)中的getFileContents函数需要读取文件,所以我不想读取这个文件两次
【问题讨论】:
标签: typescript fp-ts