Code Monkey home page Code Monkey logo

swot's Introduction

swot

swot is an Operational Transformation implementation in Swift.

Operational Transformation, often called OT, is a method that enables real-time collaboration on documents. It powers platforms like Google Docs. More information can be found on here.

Usage

// Applying a changeset
let documentT = "I'm at home"
let changesetA = Changeset(operations: [
    Keep(value: 7),
    Remove(value: 4),
    Add(value: "the beach"),
])
let documentS = try changesetA.apply(to: documentT)
// "I'm at home" -> "I'm at the beach"

// Composing changesets
let changesetB = Changeset(operations: [
    Add(value: "We're"),
    Remove(value: 3),
    Keep(value: 13),
    Add(value: " until later"),
])
let documentU = try changesetB.apply(to: documentS)
// "I'm at the beach" -> "We're at the beach until later"

let changesetC = try changesetA >>> changesetB
let documentV = try changesetC.apply(to: documentT)
// "I'm at home" -> "We're at the beach until later"

// Combining changsets
let changesetD = Changeset(operations: [
    Keep(value: 4),
    Add(value: "hanging out "),
    Keep(value: 7),
])
let documentW = try changesetD.apply(to: documentT)
// "I'm at home" -> "I'm hanging out at home"

let combined = try changesetC <~> changesetD
let documentX = try combined.right.apply(to: documentV)
// "We're at the beach until later" -> "We're hanging out at the beach until later"
let documentY = try combined.left.apply(to: documentW)
// "I'm hanging out at home" -> "We're hanging out at the beach until later"

Installing swot

swot can be installed either by copying the source code or by using the Swift Package Manager (SPM).

SPM

dependencies: [
  .package(url: "https://github.com/ireneu/swot.git", .branch("master")),
],
targets: [
	.target(name: "MyProject", dependencies: ["Swot"])
]

License

This software is licensed under the MIT License. Copyright © Ireneu Pla, 2018.

swot's People

Contributors

fromatom avatar ireneu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

fromatom

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.