You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can perform case analysis for `Json` values using the `foldJson` function.
97
+
We can perform case analysis for `Json` values using the `caseJson` function.
98
98
This function is necessary because `Json` is not an algebraic data type. If
99
99
`Json` were an algebraic data type, we would not have as much need for this
100
100
function, because we could perform pattern matching with a `case ... of`
101
101
expression instead.
102
102
103
-
The type of `foldJson` is:
103
+
The type of `caseJson` is:
104
104
105
105
```purescript
106
-
foldJson
106
+
caseJson
107
107
:: forall a
108
108
. (Unit -> a)
109
109
-> (Boolean -> a)
@@ -115,11 +115,11 @@ foldJson
115
115
-> a
116
116
```
117
117
118
-
That is, `foldJson` takes six functions, which all must return values of some
119
-
particular type `a`, together with one `Json` value. `foldJson` itself also
118
+
That is, `caseJson` takes six functions, which all must return values of some
119
+
particular type `a`, together with one `Json` value. `caseJson` itself also
120
120
returns a value of the same type `a`.
121
121
122
-
A use of `foldJson` is very similar to a `case ... of` expression, as it allows
122
+
A use of `caseJson` is very similar to a `case ... of` expression, as it allows
123
123
you to handle each of the six possibilities for the `Json` value you passed in. Thinking of it this way, each of the six function arguments is like one of the
124
124
case alternatives.
125
125
@@ -128,7 +128,7 @@ The function that takes `Unit` as an argument is for matching `null` values. As
128
128
Just like in a `case ... of` expression, the final value
129
129
that the whole expression evaluates to comes from evaluating exactly one of the
130
130
'alternatives' (functions) that you pass in. In fact, you can tell that this
131
-
is the case just by looking at the type signature of `foldJson`, because of a
131
+
is the case just by looking at the type signature of `caseJson`, because of a
132
132
property called *parametricity* (although a deeper explanation of parametricity
0 commit comments