Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/zipper

Package Overview
Dependencies
Maintainers
0
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/zipper

Functional tree editing, manipulation & navigation

  • 2.1.115
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is @thi.ng/zipper?

@thi.ng/zipper is a TypeScript library for creating and manipulating zipper data structures. Zippers are a functional programming technique for traversing and updating immutable data structures efficiently. This package provides utilities to work with tree-like structures, allowing for easy navigation, updates, and transformations.

What are @thi.ng/zipper's main functionalities?

Creating a Zipper

This feature allows you to create a zipper from a tree structure. The `fromTree` function takes a tree and a function to access the children of a node. The resulting zipper allows for efficient traversal and updates.

const { fromTree } = require('@thi.ng/zipper');
const tree = { value: 1, children: [{ value: 2 }, { value: 3 }] };
const zipper = fromTree(tree, x => x.children);
console.log(zipper.node); // { value: 1, children: [ { value: 2 }, { value: 3 } ] }

Navigating a Zipper

This feature allows you to navigate through the tree structure using the zipper. The `down` function moves to the first child, and the `right` function moves to the next sibling.

const { down, right } = require('@thi.ng/zipper');
const tree = { value: 1, children: [{ value: 2 }, { value: 3 }] };
const zipper = fromTree(tree, x => x.children);
const childZipper = down(zipper);
console.log(childZipper.node); // { value: 2 }
const siblingZipper = right(childZipper);
console.log(siblingZipper.node); // { value: 3 }

Updating a Zipper

This feature allows you to update the current node in the zipper. The `edit` function takes a zipper and a function to update the node, returning a new zipper with the updated node.

const { edit } = require('@thi.ng/zipper');
const tree = { value: 1, children: [{ value: 2 }, { value: 3 }] };
const zipper = fromTree(tree, x => x.children);
const updatedZipper = edit(zipper, node => ({ ...node, value: 42 }));
console.log(updatedZipper.node); // { value: 42, children: [ { value: 2 }, { value: 3 } ] }

Other packages similar to @thi.ng/zipper

Keywords

FAQs

Package last updated on 10 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc