monocle-tsでtraverse

ネストした配列の中身をfilterしつつ色々できる

type User = {
    friendNames: string[]
}

const user = {
    friendNames: ["bob", "john"]
}

import { Lens, fromTraversable } from "monocle-ts"
import { array } from "fp-ts/lib/Array";

Lens.fromProp<User>()("friendNames")
    .composeTraverse(fromTraversable(array).filter(n => n === "bob"))
    .modify(n => n.toUpperCase())
// => { friendNames: ["BOB", "john"]}

Googleがinterfaceを好む理由 react digraph使い方 TypeScriptとHigher Kinded Type(高階型)
View Comments
There are currently no comments.