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
Copy file name to clipboardExpand all lines: README.md
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -319,9 +319,12 @@ assert xs is Nothing
319
319
320
320
### Option as an applicative
321
321
322
-
In functional programming, we sometimes want to combine two Option values into a new Option. However, this combination should only happen if both Options are Some. If either Option is None, the resulting value should also be None.
322
+
In functional programming, we sometimes want to combine two Option values into a new Option. However, this combination
323
+
should only happen if both Options are Some. If either Option is None, the resulting value should also be None.
323
324
324
-
The map2 function allows us to achieve this behavior. It takes two Option values and a function as arguments. The function is applied only if both Options are Some, and the result becomes the new Some value. Otherwise, map2 returns None.
325
+
The map2 function allows us to achieve this behavior. It takes two Option values and a function as arguments. The
326
+
function is applied only if both Options are Some, and the result becomes the new Some value. Otherwise, map2 returns
327
+
None.
325
328
326
329
This approach ensures that our combined value reflects the presence or absence of data in the original Options.
327
330
@@ -414,7 +417,7 @@ type union `(A | B)` are both types, while the cases in a tagged union type `U =
414
417
are both constructors for the type U and are not types themselves. One consequence is
415
418
that tagged unions can be nested in a way union types might not.
416
419
417
-
In Expression you make a tagged union by defining your type similar to a dataclass and
420
+
In Expression you make a tagged union by defining your type similar to a `dataclass` and
418
421
decorate it with `@tagged_union` and add the appropriate generic types that this union
419
422
represent for each case. Then you optionally define static or class-method constructors
420
423
for creating each of the tagged union cases.
@@ -456,7 +459,7 @@ check correctly when pattern matching. The `tag` field if specified should be a
456
459
type with all the possible values for the tag. This is used by static type checkers to
457
460
check exhaustiveness of pattern matching.
458
461
459
-
Each case is given the `case()` field initializer. This is optioal, but recommended for
462
+
Each case is given the `case()` field initializer. This is optional, but recommended for
460
463
static type checkers to work correctly. It's not required for the code to work properly,
461
464
462
465
Now you may pattern match the shape to get back the actual value:
0 commit comments