Git Product home page Git Product logo

commutable's Introduction

com·mut·a·ble

Build Status codecov

/kəˈmyo͞otəbəl/

  1. (of a place or journey) allowing regular commuting to and from work.
  2. capable of being exchanged or converted.

commutable is a library for Jupyter Notebook operations, helping to enable history stored as a series of immutable notebooks.

Principles

  • A notebook document is immutable. It is never mutated in-place.
  • Changes to a notebook document are encapsulated into operations that take a previous version and return a new one.
  • History is represented as a list of states, with past on one end, the present on the other, and an index that can back up into 'undo states'.
  • Modifying a notebook document causes any future states to be thrown away.

Credits to Tom MacWright for the outline.

Installation

npm install --save commutable

Usage

Fresh notebook

> const uuid = require('uuid').v4
undefined
> const commutable = require('.')
undefined
> nb = commutable.emptyNotebook
Map { "cellOrder": List [], "nbformat": 4, "nbformat_minor": 0, "cellMap": Map {} }

> cellID = uuid()
'd50dbdd5-1af0-4c8d-90fb-ae9ed9ff6c9b'

> nb2 = commutable.appendCell(nb, commutable.emptyCodeCell, cellID)
> nb2.toJS()
{ cellOrder: [ 'd50dbdd5-1af0-4c8d-90fb-ae9ed9ff6c9b' ],
  nbformat: 4,
  nbformat_minor: 0,
  cellMap:
   { 'd50dbdd5-1af0-4c8d-90fb-ae9ed9ff6c9b':
      { cell_type: 'code',
        execution_count: null,
        metadata: [Object],
        source: '',
        outputs: [] } } }

> nb3 = commutable.appendCell(nb2,
... commutable.emptyCodeCell.set('source', 'import random\nrandom.random()'), uuid())
> nb3.toJS()
{ cellOrder:
   [ 'd50dbdd5-1af0-4c8d-90fb-ae9ed9ff6c9b',
     '8d40321c-87c0-4d86-900c-2174f6920969' ],
  nbformat: 4,
  nbformat_minor: 0,
  cellMap:
   { 'd50dbdd5-1af0-4c8d-90fb-ae9ed9ff6c9b':
      { cell_type: 'code',
        execution_count: null,
        metadata: [Object],
        source: '',
        outputs: [] },
     '8d40321c-87c0-4d86-900c-2174f6920969':
      { cell_type: 'code',
        execution_count: null,
        metadata: [Object],
        source: 'import random\nrandom.random()',
        outputs: [] } } }

commutable's People

Contributors

betatim avatar captainsafia avatar ivanov avatar jdetle avatar jdfreder avatar kenwheeler avatar lgeiger avatar rgbkrk avatar

Watchers

 avatar

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.