fp-tsの続き
1
昨日の続きです。
昨日のShowはあくまで標準主力にOutputされることを意識したインターフェースでした。
これです。
export class Show<A> { public readonly _tag: 'Show' = 'Show'; public readonly _A!: A; public readonly _URI!: FsFURI; constructor(readonly message: string, readonly more: A) {} }
これをWriterのようにあとですべてのmessageを取得するように変えたい時にどうすれば良いでしょうか。
実はinterpretTaskEither
がTaskEither<string, A>
というMonadになっているのは、Free型を解いていく際にMonadのchainを使って継続させているためのなのです。
昨日のfoldFree
の第一引数がMonadになっているのはそう言った理由です。
一旦
function tell(message: string) { return function<A>(x: A) { return free.liftF(new Show(message, x)); } } const program = read('./package.json').chain(content => tell(content)(content)).chain(content => write('./package2.json', content)));
と書き換えてみます。
今回のShow型のmessageがstring[]
というMonoidに足されていくように解釈して欲しいので
TaskEither型にWriterTを使って TaskWriterEither<string, string[], A>
のような型とMonadにするためのchain関数があればいいのですが
すみません!!!時間不足でできませんでした!!!