GithubHelp home page GithubHelp logo

purescript / purescript-record Goto Github PK

View Code? Open in Web Editor NEW
70.0 11.0 31.0 66 KB

Functions for working with records and polymorphic labels

License: BSD 3-Clause "New" or "Revised" License

PureScript 93.46% JavaScript 6.54%

purescript-record's Introduction

purescript-record

Latest release Build status Pursuit

Functions for working with records and polymorphic labels

Installation

spago install record

Examples

Given some Symbol ("type level String") Proxy and a constrained or concrete record type, you can use this library to generically modify records.

x_ = Proxy :: Proxy "x"

-- we can get a value out of a field
gotX :: Int
gotX = Record.get x_ { x: 1 }

-- we can insert a value into a record that does not have a field at that label yet
insertedX :: { x :: Int }
insertedX = Record.insert x_ 1 {}

-- we can delete a field from a record at a specific label
deletedX :: {}
deletedX = Record.delete x_ { x: 1 }

-- we can set a new value for a field
setX1 :: { x :: Int }
setX1 = Record.set x_ 1 { x: 0 }

-- we can also modify the type of the field by replacing the contents
setX2 :: { x :: Unit }
setX2 = Record.set x_ unit { x: 0 }

-- we can modify the field value with a function
modifyX :: { x :: Int }
modifyX = Record.modify x_ (\value -> value + 1) { x: 0 }

-- we can also merge two records
mergedXY :: { x :: Int , y :: Int }
mergedXY = Record.merge { x: 1 } { y: 1 }

See the tests for more examples.

If you need to combine multiple operations and avoid intermediate values, you might consider using Record.Builder.

You can also find an explanation and example of how to use this library in this tutorial of the Simple-JSON docs.

Documentation

Module documentation is published on Pursuit.

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.