3

I am first about the Purescript. I am going to add the new field to Object and send it as a function param. But I can not find a good solution for this.

For example.

oldFiled = {
 title : "title",
 description : "d" 
}
newField = {
  time : "time"
}
//result after added new field
oldFiled = {
  title : "title",
  description : "d",
  time : "time"
}

How can I do it?

1 Answer 1

3

If it's just about adding a single field you can use https://pursuit.purescript.org/packages/purescript-record/2.0.1/docs/Record#v:insert like so:

import Data.Record as Record
import Data.Symbol (SProxy(..))
oldFiled = {
 title : "title",
 description : "d" 
}
newFiled = Record.insert (SProxy :: _ "time") "time" oldFiled

If you're merging records look at the merge union and disjointUnion functions in the Data.Record module

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.