Skip to content

[Js.Obj]: add immutable assign function #795

@anmonteiro

Description

@anmonteiro
  • Object.assign is mutable
  • a common idiom is Object.assign({}, foo, bar) to create a new object

the Js.Obj module could have a function that does this. e.g.:

external assignImm :
  (_[@mel.as {json|{}|json}]) -> < .. > Js.t -> < .. > Js.t -> < .. > Js.t
  = "Object.assign"

let () = Js.log (assignImm [%mel.obj { foo = 1 }] [%mel.obj { bar = 2 }])
$ melc -ppx melppx x.ml
// Generated by Melange
'use strict';


console.log(Object.assign({}, {
          foo: 1
        }, {
          bar: 2
        }));

/*  Not a pure module */

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions