Giter VIP home page Giter VIP logo

structural's Introduction

structural

Structural diff, merge, patch, pick, and mask helpers for CUE.

MVS will make using cue modules easier.

Index

support for both Cue and Go vals/structs

  1. Usage
  2. equal
  3. diff
  4. merge
  5. patch
  6. pick
  7. mask
  8. Developing

Usage

structural is most easily used with cue modules, see https://github.com/hofstadter-io/mvs.

Initialize a cue module

mvs init cue github.com/<namespace>/<project>

Add structural to your cue.mods file:

require github.com/hofstadter-io/structural v0.0.3

Update your dependencies:

mvs vendor

After creating example.cue (see below) run the following:

cue eval example.cue
cue export example.cue

Look for a "same" field == true

example.cue

import "github.com/hofstadter-io/structural"

A :: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
}
B :: {
	b: "b"
	c: "c"
	N: {x: "x", z: "z"}
}

diff: {
  same: (ex & an) != _|_
  ex: (structural.Diff & {Orig: A, New: B}).Result
  an: {
    "[]": {
      removed: {
        a: "a"
      }
      added: {
        c: "c"
      }
    }
    "[\"N\"]": {
      removed: {
        y: "y"
      }
      added: {
        z: "z"
      }
    }
  }
}

merge: {
  same: (ex & an) != _|_
  ex: (structural.Merge & {Orig: A, New: B}).Result
  an: {
    a: "a"
    b: "b"
    c: "c"
    N: {
      x: "x"
      y: "y"
      z: "z"
    }
  }
}

Diff

Diff :: {
	// Arguments
	Orig: {...}
	New:  {...}

	Result: {...}
}
A :: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
}
Z :: {
	a: "a"
	b: "b"
	N: "N"
}
x: (structural.Diff & {Orig: A, New: Z}).Result
x: {
	changed: {
	  N: {
	    from: {
	      x: "x"
	      y: "y"
	    }
	    to: "N"
	  }
	}
}

Merge

Merge :: {
	// Arguments
	Orig: {...}
	New:  {...}

	Result: {...}
A :: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
}
B :: {
	b: "b"
	c: "c"
	N: {x: "x", z: "z"}
}
x: (structural.Merge & {Orig: A, New: B}).Result
x: {
  a: "a"
  b: "b"
  c: "c"
  N: {
    x: "x"
    y: "y"
    z: "z"
  }
}

Patch

Patch :: {
	// Arguments
	Orig: {...}
	Diff: {...}

	Result: {...}
}
x: (structural.Patch & {Orig: {a: "a", b: "b", y: "y", N: {x: "x"}},
												 Diff: {inplace: {N: {changed: {x: {from: "x", to: "xx"}}}}, changed: {y: {from: "y", to: "yy"}}, removed: {b: "b"}, added: {z: "z"}}}).Result
x: {a: "a", y: "yy", N: {x: "xx"}, z: "z"}

Pick

Pick :: {
	// Arguments
  Orig: {...}
  Pick: {...}

  Result: {...}
}
X:: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
	l: [1, 2, 3, 4, 5]
}
x: (structural.Pick & {Orig: X, Pick: { b: string, N: {x: string}, l: [1, 1, 3] }}).Result
x: {
  b: "b"
  N: {
    x: "x"
  }
  l: [1, 3]
}

Mask

Mask :: {
	// Arguments
  Orig: {...}
  Mask: {...}

  Result: {...}
}
X:: {
	a: "a"
	b: "b"
	N: {x: "x", y: "y"}
	l: [1, 2, 3, 4, 5]
}
x: (structural.Mask & {Orig: X, Mask: { b: string, N: {x: string}, l: [1, 1, 3] }}).Result
x: {
	a: "a"
	N: {
		y: "y"
	}
	l: [2, 4, 5]
}

Developing

There isn't much special, you just need cue installed.

Running tests

cue test

See the test directory for more specifics and examples.

This runs the test command in test_tool.cue which is nothing more than "cue export test/*.cue"

structural's People

Contributors

philipdexter avatar verdverm avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mrcllnz

structural's Issues

docs

@philipdexter can you take a first pass at this?


README.md format:

# structural

<intro blurb> // add pick, mask to the comma separated list

### Index

<index>

### Usage

<existing-usage>

### <section>
...
x5
...

### Developing

<existing-developing>

Where each <section> is for one of the five "functions" with the following format:


### <function-name>

`<"Signature">` // not sure what this looks like yet

<blurb>

<example-with-code-block>

and Index is:

- [FunctionName](#<function-name>) - `<"Signature">`

this # business should line up with the section title, replacing spaces with - and all lower case I believe, like an in-page link / anchor. You can mouse hover over a section title with ### to see the link value, you should only need the #... part in the markdown for the [Link Text](link-href)


( don't you just love how I partial templated markdown in a github issue ;)

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.