1# purescript-record-studio ๐๐๐
3You finally scored a record deal.
7### Assert two records have the same keys with `SameKeys`
10-- An example of a function that requires `{|r1}` and `{|r2}` to have the same keys
11sameKeys :: forall r1 r2. SameKeys r1 r2 => {|r1} -> {|r2} -> Unit
13let _ = sameKeys { b: "hi", a: 4, c: 4 } { b: "hu", a: "ha" }
14-- Won't compile: The key "c" is missing from the second record
17### Merge records with `//`
18Easily merge two records:
21{ a: 5, b: "B" } // { b: false, c: "c" }
22-- { a: 5, b: false, c: "c" }
25This is similar to the `...` operator in ES6:
29import Record.Studio ((//))
38const rec2 = { b: 4, c: 8 }
39const result = { ...rec1, ...rec2 }
42### Shrink records with `shrink`
43Easily adjust a record with too many keys:
45import Record.Studio (shrink)
46-- We want to call this
47-- fn :: { a :: Int } -> Int
50myRec :: { a :: Int, b :: String }
51myRec = { a: 4, b: "Hello!" }
54result = fn (shrink myRec)
57### Get a record's keys at runtime with `keys`
59import Record.Studio (keys)
61theKeys :: Array String
62theKeys = keys { a: 3, b: "ooh" }
67Recursively sequence a type constructor out of a record.
71 input :: SequenceInput
83 expected :: Maybe SequenceOutput
94(sequenceRecord input) `shouldEqual` expected
99Recursively map a function over a record where all entries have the same value.
100This is often better at type inference than `mapRecord`
102 (mapUniformRecord (_ + 1) { a: 1, b: 2 }) `shouldEqual` { a: 2, b: 3}
107Recursively map a function over a record.
117 , f: { g: true, h: 30 }
125 expected :: MapOutput
132 , f: { g: true, h: "31" }
136(mapRecord f input) `shouldEqual` expected
141Recursively map a natural transformation over a record.
152 , f: { g: Right true, h: Left "broken" }
157 nt :: Either String ~> Maybe
160 expected :: MapKOutput
167 , f: { g: Just true, h: Nothing }
171(mapRecordKind nt input) `shouldEqual` expected
176Get the only field name of a Record with one field as a `Proxy`
179SingletonRecord.key { foo: unit } `shouldEqual` (Proxy :: Proxy "foo")
183This is a fork of [heterogeneous-extrablatt](https://github.com/sigma-andex/purescript-heterogeneous-extrablatt), which is licenced under MIT. See the [original licence](./LICENCES/heterogeneous-extrablatt.LICENCE). This work is similarly licenced under [MIT](./LICENCE).
184It includes part of [`purescript-record-extra`](https://github.com/justinwoo/purescript-record-extra) as an inline dependency, which is licenced under MIT, see [original licence](./LICENCES/record-extra.LICENCE).
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list