简体   繁体   中英

How to partially update a purescript record

everyone!

I'm a Purescript beginner and have trouble with working on records.

I have one record type:

type Employee =
 { firstName :: String
 , lastName :: String
 , address :: String
 , height :: Number
 , weight :: Number
 ...
 }

And I want to update just a portion of this record. Let's say I want to only update height like the following typescript code.

let a: Employee = {
 ...a,
 height: 180
}

How can I achieve this in Purescript? Thank you.

Syntax for record update in PureScript is the following:

r2 = r1 { x = 42, y = "foo" }

Where:

  • r1 is the original record
  • r2 is the new, updated record
  • x and y are record fields ( not necessarily ALL fields )

The above snippet is equivalent to the following JavaScript code:

r2 = { ...r1, x: 42, y: "foo" }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM