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();
In the example above since Article
requires 2 params that are side-effects. The question is on createArticle
and if that could be written as a point free function.