Git Product home page Git Product logo

reactivesets's Introduction

Introduction

Reactive Sets provides a declarative way to describe relationships between sets and have those relationships automatically maintained over time.

Whereas LINQ allows you to describe a transformation of a collection and perform that transformation once and Rx allows you to describe a transformation on a single value and have that transformation re-applied every time the value changes, Reactive Sets combines both these powers. You use a LINQ like syntax to describe a transformation of a collection and ReactiveSets ensures that the transformation is re-applied as the contents of the source collection change over time.

Practically speaking, Reactive Sets is mostly a set of extension methods on the type IObservable<IDelta<TId, TPayload>>. IDelta<TId, TPayload> is a struct describing a mutation to a set of items (add an item, remove an item, clear etc.). As in LINQ and Rx, the extension method usually returns a similar type so chaining is possible.

Here is a small example:

// a set mapping stock ticker to current price
var stockPrices = new Set<string, double>();
// a set mapping stock ticker to number of stocks owned
var positions = new Set<string, int>();

positions                
    // join the two sets by stock ticker (the Id), multiplying the values
    // to give us a set of stock ticker to current value of the owned stocks
    .Join(stockPrices, (position, price) => position * price)
    // sum value over all stocks owned
    .Aggregate(vs => vs.Sum())
    // print the total value to the console each time it changes
    .Subscribe(Console.WriteLine);

// changes to stock prices and stocks owned
// automatically update the total value
stockPrices.SetItem("GOOG", 500);
positions.SetItem("GOOG", 10);
stockPrices.SetItem("AAPL", 1000);
positions.SetItem("AAPL", 10);
stockPrices.SetItem("AAPL", 1001);
positions.DeleteItem("AAPL");

// prints:
// 0
// 0
// 5000
// 15000
// 15010
// 5000

reactivesets's People

Contributors

felixwatts avatar

Watchers

 avatar James Cloos 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.