Giter Site home page Giter Site logo

fp-ts-graph's Introduction

no-day

After midnight of every day. Technically it's the next day, but doesn't the next day really start when you wake up in the morning?

Docs

Early prototype

This repo contains a very early prototype of the no-day graph editor.

Run the UI on the current repo

git clone https://github.com/no-day/no-day
cd no-day
yarn install
yarn no-day

The UI is served on port 9000.

Run the UI on another local repo

Currently we don't provide an installer, but you can:

ln -fs $PWD/node_modules/.bin/no-day ~/bin/no-day

And from another monorepo then run:no-day at the root.

fp-ts-graph's People

Contributors

ericcrosson avatar m-bock avatar randomf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fp-ts-graph's Issues

package.json `types` and `main` do not point to files

Excerpt from the published package.json

{
  "types": "dist/index.d.ts",
  "main": "dist/index.js",
}

Both of these files do not exist, see the tree of the bundle provided by npm

$ tree ../node_modules/@no-day/fp-ts-graph/            
../node_modules/@no-day/fp-ts-graph/
├── dist
│   └── src
│       ├── index.d.ts
│       └── index.js

The solution I know is to update the package.json like so

{
  "types": "dist/src/index.d.ts",
  "main": "dist/src/index.js",
}

Going to work on a PR

Refactor & completion of CRUD operations

I'd like to make the CRUD operations for edges and nodes more explicit.

Types

Here's a draft for the operations with their planned return types:

Node

  • C: insertNode : Either<ErrNodeExists, Graph<...>>
  • R: lookupNode : Either<ErrNodeNotExists, Node>
  • U: updateNode, modifyNode : Either<ErrNodeNotExists, Graph<...>>
  • D: deleteNode : Either<ErrNodeNotExists, Graph<...>>
  • (CU: upsertNode : Graph<...>, "the only one that can never fail")

Edge

  • C: insertEdge : Either<ErrNodeNotExists | ErrEdgeExists, Graph<...>>
  • R: lookupEdge : Either<ErrEdgeNotExists, Graph<...>>
  • U: updateEdge, modifyEdge : Either<ErrEdgeNotExists, Graph<...>>
  • D: deleteEdge : Either<ErrEdgeNotExists, Graph<...>>
  • (CU: upsertEdge : Either<ErrNodeNotExists, Graph<...>>)

Thoughts

  • Another option would be to keep operations that can only fail by one cause (almost all of them) in Option instead of Either. That's quite common, but to me it looks more consistent to keep all of them in Either.
  • First I was in favor of using the "at" like in fp-ts/Map: insertAt would be insertAtNode, but looking at the above bullets, it seems to me more confusing than helping.

Improve performance of graph operations

Due to underlying data structures (Map) it takes O(n) to lookup a node in the graph. fp-ts iterates the map one by one and uses Eq to match the node. This is extremely limiting when having large graphs (thousands+ of nodes) and performing complex traverse operations.

Suggested improvements:

  1. Provide io-ts codec which encodes / decodes arbitrary data type to string
  2. Replace all occurances of Map with Record and use encoded strings as keys (lookup complexity between O(1) and O(log(n)))
import { Codec } from 'io-ts/Codec';

export interface Graph<Id, Edge, Node> {
  readonly _brand: unique symbol;
  readonly nodes: Record<string, NodeContext<Node>>;
  readonly edges: Record<string, Edge>;
}

type NodeContext<Node> = {
  data: Node;
  outgoing: Set<string>;
  incoming: Set<string>;
};

Usually only first function argument changes from E: Eq<Id> to C: Codec<string, string, Id>. The remaining arguments should remain the same same . The only problem I see is with potential collision when building what's been Direction<T> = { from: T, to: T } and now is string out of two strings (using derived Codec<string, string, string>. We can use some non-standard sequence of UTF characters which is highly unlikely to collide and write an explicit warning in the documentation.

Let me know your thoughts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.