如何将其转换为 Point-free 函数

How do I convert this to a Point-free function

import { chain, map, Apply } from "fp-ts/lib/IO";
import { log } from "fp-ts/lib/Console";
import { pipe } from "fp-ts/lib/function";
import * as D from "fp-ts/lib/Date";
import { sequenceT } from "fp-ts/lib/Apply";
import { v4 as uuidv4 } from "uuid";

export const Article = (title: string) =>
  ([id, now]: [string, Date]) => ({
    id,
    title,
    createdAt: now
  });

const createArticle = (title: string) =>
  pipe(sequenceT(Apply)(uuidv4, D.create), map(Article(title)));

const program = pipe(
  createArticle("hello"),
  chain(log)
);

program();

在上面的示例中,因为 Article 需要 2 个副作用参数。问题是 createArticle 是否可以将其写成无点函数。

您可以通过使用 ap 将值应用于函数来反向进行管道传输。我必须创建一个函数来帮助 TypeScript 确定 of.

的类型
import { chain, map, Apply, of, ap } from "fp-ts/lib/IO";
import { log } from "fp-ts/lib/Console";
import { flow, pipe } from "fp-ts/lib/function";
import * as D from "fp-ts/lib/Date";
import { sequenceT } from "fp-ts/lib/Apply";
import { v4 as uuidv4 } from "uuid";

const Article =
  (title: string) =>
  ([id, now]: [string, Date]) => ({
    id,
    title,
    createdAt: now,
  });

const ofString = (str: string) => of(str);

const createArticle = flow(
  ofString,
  map(Article),
  ap(sequenceT(Apply)(uuidv4, D.create))
);

const program = pipe(createArticle("hello"), chain(log));

program();