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"]}

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