reasonml / reasonml/reason

Syntax sugar for (immutably) modifying js-objects

Open
#2,467 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
10.3k
Forks
438
PR merge metrics
No merged PRs in 30d

Description

We have {"key": value} syntax sugar for creating JavaScript-objects. With records we have syntax to immutably update a record:

let meNextYear = {...me, age: me.age + 1};

For JavaScript interop it would be great to have similar syntax for objects, something like:

let meNextYear = {...me, "age": me##age + 1};

This because it's not possible to have a single function to update an object due to the typesystem. And Js.Obj.assign loses type information (see below).

Js.Obj.empty()->Js.Obj.assign(me)->Js.Obj.assign({"age": me##age + 1})

I am not sure if this is something very hard as it might need modification pretty deep inside of the (ocaml) compiler. But it would be great to have a good solution for this, JS-objects are still used in many libraries even if you don't interop with existing JavaScript code.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing record update syntax and the Js.Obj.assign examples described in the issue. The issue names no files or tests; done would require an agreed syntax for immutable JavaScript-object updates that preserves useful type information.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, ocaml
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.