GithubHelp home page GithubHelp logo

juspay / jrec Goto Github PK

View Code? Open in Web Editor NEW
36.0 17.0 6.0 101 KB

Literally the best anonymous records

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

Haskell 99.40% Nix 0.52% Shell 0.08%
haskell records

jrec's Introduction

jrec — anonymous records for busy people

Based on superrecord, but simplified. No automatic field reordering. No GHCJS bits inside. Easier to hack on.

Benefits

  • Nice construction syntax:

    Rec (#id := 18853, #orderId := "MG13-233")
  • Provides Generic instances out of the box. Aeson, etc can't believe these aren't normal records! Anything Generic-derived just works.

  • Provides generic-lens and generic-optics instances out of the box. Due to those custom instances, we support polymorphic updates.

  • O(1) field access, O(n) construction.

  • PureScript-style partial records — if you have a Rec ("foo" := Int ': rest), HasField "foo" will work just fine.

Developing

IDE support is available inside nix-shell. For example, if you use VS Code, you may launch it as:

nix-shell --run "code ."

Tests

Run bin/test for fast-reloading tests. When library sources change, the test script will reload instantly and re-run the tests.

TODOs

  • Documentation.
  • Expose all internals.
  • -- NOTE: doesn't use 'KeyDoesNotExist' — fix this.
  • RemoveAccessTo — can we get rid of it?

Acknowledgement

  • The JRec.Internal module is entirely based on the code from superrecord.

jrec's People

Contributors

avnik avatar conscious-puppet avatar ilyakooo0 avatar kamoii avatar neongreen avatar srid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jrec's Issues

[Question] Stance about key duplication

I have a question about the stance of the library against key dupclication.

Currently, there is no key duplication check on construct, and the operators work even if there is a key duplication.
There is a metion in the README about fixing KeyDoesNotExist and RemoveAccessTo, which I guess you want to get rid of key duplication. But then there are operators like append that could bring in key duplication.
So which stance does the library have(or will have) against key duplication?

  1. Prevent key duplication by adding key check constraints on construct functions/instances and make sure operations don't bring in key duplication.
  2. Adding key check constraints are costly, so don't. Make the operation works even if there ia an accidentaly brought in key duplication.

Better errors when value types don't match?

> Rec (#a := 3, #b := True) :: Rec '["a" := Int, "b" := String]

<interactive>:1:1: error:
    • Couldn't match type ‘Bool’ with ‘[Char]’
        arising from a use of ‘Rec’
    • In the expression:
          Rec (#a := 3, #b := True) :: Rec '["a" := Int, "b" := String]
      In an equation for ‘it’:
          it = Rec (#a := 3, #b := True) :: Rec '["a" := Int, "b" := String]

Is it possible to provide the key in the error message as well?

Merging and consing

Vague inspiration: https://pursuit.purescript.org/packages/purescript-record/0.2.6/docs/Data.Record

Not sure about all of this, but:

  • union appends records and removes duplicates. Left-biased. Does not sort.
  • append appends records and does not remove duplicates.
  • insert adds a field to the beginning, but checks that the record does not contain that field already.
  • insertOrSet adds a field to the beginning, or replaces the existing field.

There have to be tests for all of these, including

added by srid:

  • Fix a bug with append overwriting values (looks to affect Eq as well; ultimately because of RecTyIdxH)
  • Finish tests

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.