I have the following code
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)
);
above function getPostData()
retun
IO<{
data: {[key: string]: any};
id: string;
}>
Now I have to add some fileds in the returned result, let's say content
, and the result looks like
IO<{
data: {[key: string]: any};
id: string;
content: string;
}>
I write a new function getContent = (matter: matter.GrayMatterFile<string>) => {...}
, Now how to add this function to the combined function getPostData
?
The main question I want to ask is how to divide the values into different functions for processing in the combined function.
Because the getFileContents
function in chain(getFileContents)
needs to read the file, I don't want to read this file twice