npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rescript-digraph

v1.0.0

Published

Functional-style directed graph implementation in ReScript

Readme

Digraph: Directed Graph

Functional-style directed graph implementation in ReScript

Due to performance concerns unfortunately it is not purely functional, so insertions and deletions modify the underlying Maps.

Installation

npm install rescript-digraph

Construction

Digraph.make

Creates a new directed graph.

let make: unit => Digraph.t

Usage

let graph = Digraph.make()

Digraph.insertVertex

Inserts a new vertex into the graph.

let insertVertex: (Digraph.t, 'vertexData) => Digraph.t

Usage

// String vertex data
let graph = Digraph.insertVertex(Digraph.make(), "Jane")
// Number vertex data
let graph = Digraph.insertVertex(Digraph.make(), 42)
// Custom type vertex data
type vertexData = {id: int, name: string}
let graph = Digraph.insertVertex(Digraph.make(), {id: 1, name: "Alice"})

Digraph.insertEdge

Inserts a new edge into the graph. Returns the unmodified graph if the edge already exists or vertex does not exist.

let insertEdge: (Digraph.t, int, int, 'edgeData) => Digraph.t

Usage

// Unit edge data
let graph = Digraph.insertEdge(Digraph.make(), 0, 1, ())
// Number edge data, could be used as weight for example
let graph = Digraph.insertEdge(Digraph.make(), 0, 1, 42)
// Custom type edge data
type relationship = Sibling | Cousin
type edgeData = {weight: int, relationship: relationship}
let graph = Digraph.make()
  ->insertEdge(0, 1, {weight: 5, relationship: Sibling})
  ->insertEdge(1, 0, {weight: 10, relationship: Cousin})

Digraph.deleteVertex

Deletes a vertex from the graph. Returns the unmodified graph if the vertex does not exist. Also deletes all the edges connected to the vertex.

let deleteVertex: (Digraph.t, int) => Digraph.t

Usage

let graph = Digraph.make()
  ->insertVertex("Jane")
  ->insertVertex("Mary")
let graph = Digraph.deleteVertex(graph, 0)

Digraph.deleteEdge

Deletes an edge from the graph. Returns the unmodified graph if the edge does not exist.

let deleteEdge: (Digraph.t, int, int) => Digraph.t

Usage

let graph = Digraph.make()
  ->insertVertex("Jane")
  ->insertVertex("Mary")
  ->insertEdge(0, 1, ())
let graph = Digraph.deleteEdge(graph, 0, 1)

Querying

Digraph.getVertex

Retrieves the data associated with a vertex.

let getVertex: (Digraph.t, int) => option<'vertexData>

Usage

let graph = Digraph.make()
  ->insertVertex("Jane")
  ->insertVertex("Mary")
let jane = Digraph.getVertex(graph, 0)

Digraph.getEdge

Retrieves the data associated with an edge.

let getEdge: (Digraph.t, int, int) => option<'edgeData>

Usage

type relationship = Sibling | Cousin
type edgeData = {weight: int, relationship: relationship}

let graph = Digraph.make()
  ->insertVertex("Jane")
  ->insertVertex("Mary")
  ->insertEdge(0, 1, {weight: 5, relationship: Sibling})
let janeMaryRelationship = Digraph.getEdge(graph, 0, 1)

Map and Filter

Digraph.mapVertex

Each vertex is transformed by the provided function.

let map: (Digraph.t, ('vertexData => 'newVertexData)) => Digraph.t

Usage

let graph = Digraph.make()
  ->insertVertex("Jane")
  ->insertVertex("Mary")
let newGraph = Digraph.mapVertex(graph, (data) => data ++ " Smith")

Digraph.mapEdges

Each edge is transformed by the provided function.

let mapEdges: (Digraph.t, ('edgeData => 'newEdgeData)) => Digraph.t

Usage

let graph = Digraph.make()
  ->insertVertex("Jane")
  ->insertVertex("Mary")
  ->insertEdge(0, 1, {weight: 5, relationship: Sibling})
let newGraph = Digraph.mapEdges(graph, (data) => {data with weight: data.weight + 1})

Digraph.filterVertex

Return a new graph containing only the vertices that satisfy the predicate.

let filterVertex: (Digraph.t, ('key, 'vertexData => bool)) => Digraph.t

Usage

let graph = Digraph.make()
  ->insertVertex("Jane")
  ->insertVertex("Mary")
let filteredGraph = Digraph.filterVertex(graph, (key, data) => data == "Jane")