目次
monocle-tsでtraverse
Kazuki Moriyama (森山 和樹)
type User = {
friendNames: string[];
};
const user = {
friendNames: ["bob", "john"],
};
import { Lens, fromTraversable } from "monocle-ts";
import { array } from "fp-ts/lib/Array";
// Filter and modify the nested array
Lens.fromProp<User>()("friendNames")
.composeTraverse(fromTraversable(array).filter(n => n === "bob"))
.modify(n => n.toUpperCase());
// => { friendNames: ["BOB", "john"]}