Skip to content

Commit 83d8de5

Browse files
Zelenyamilesfrain
authored andcommitted
[Chapter 10] De-pointfree mapSetFoo function
1 parent eea2f4b commit 83d8de5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

exercises/chapter10/test/Examples.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ addComplexDecoded a b = decodeJson $ addComplexJson a b
124124
foreign import mapSetFooJson :: Json -> Json
125125

126126
mapSetFoo :: Map String Int -> Either JsonDecodeError (Map String Int)
127-
mapSetFoo = encodeJson >>> mapSetFooJson >>> decodeJson
127+
mapSetFoo json = decodeJson $ mapSetFooJson $ encodeJson json
128128
-- ANCHOR_END: mapSetFooJson
129129

130130
{-

text/chapter10.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ $ spago repl
839839
(Right { imag: 6.0, real: 4.0 })
840840
```
841841

842-
Using JSON is also the easiest way to pass other structural types, such as `Map` and `Set` through the FFI. Note that since JSON only consists of booleans, numbers, strings, arrays, and objects of other JSON values, we can't write a `Map` and `Set` directly in JSON. But we can represent these structures as arrays (assuming the keys and values can also be represented in JSON), and then decode them back to `Map` or `Set`.
842+
Using JSON is also the easiest way to pass other structural types, such as `Map` and `Set`, through the FFI. Since JSON only consists of booleans, numbers, strings, arrays, and objects of other JSON values, we can't write a `Map` and `Set` directly in JSON. But we can represent these structures as arrays (assuming the keys and values can also be represented in JSON) and then decode them back to `Map` or `Set`.
843843

844844
Here's an example of a foreign function signature that modifies a `Map` of `String` keys and `Int` values, along with the wrapper function that handles JSON encoding and decoding.
845845

@@ -857,7 +857,7 @@ mapSetFoo :: Map String Int -> Either JsonDecodeError (Map String Int)
857857
mapSetFoo = encodeJson >>> mapSetFooJson >>> decodeJson
858858
```
859859

860-
Here is the JavaScript implementation. Note the `Array.from` step which is necessary to convert the JavaScript `Map` into a JSON-friendly format before decoding converts it back to a PureScript `Map`.
860+
Here is the JavaScript implementation. Note the `Array.from` step, which is necessary to convert the JavaScript `Map` into a JSON-friendly format before decoding converts it back to a PureScript `Map`.
861861

862862
```js
863863
export const mapSetFooJson = j => {

0 commit comments

Comments
 (0)