|
20 | 20 | - [`Option.getOr`](#optiongetor) |
21 | 21 | - [`Option.getOrWith`](#optiongetorwith) |
22 | 22 | - [`null`](#null) |
| 23 | + - [`nullAsOption`](#nullasoption) |
23 | 24 | - [`nullable`](#nullable) |
24 | 25 | - [`nullableAsOption`](#nullableasoption) |
25 | 26 | - [`unit`](#unit) |
@@ -403,20 +404,35 @@ Also you can use `Option.getOrWith` for lazy evaluation of the default value. |
403 | 404 |
|
404 | 405 | ### **`null`** |
405 | 406 |
|
406 | | -`S.t<'value> => S.t<option<'value>>` |
| 407 | +`S.t<'value> => S.t<null<'value>>` |
407 | 408 |
|
408 | 409 | ```rescript |
409 | 410 | let schema = S.null(S.string) |
410 | 411 |
|
| 412 | +"Hello World!"->S.parseOrThrow(schema) |
| 413 | +// Value("Hello World!") |
| 414 | +%raw(`null`)->S.parseOrThrow(schema) |
| 415 | +// Null |
| 416 | +``` |
| 417 | + |
| 418 | +The `S.null` schema represents a data of a specific type that might be null. |
| 419 | + |
| 420 | +### **`nullAsOption`** |
| 421 | + |
| 422 | +`S.t<'value> => S.t<option<'value>>` |
| 423 | + |
| 424 | +```rescript |
| 425 | +let schema = S.nullAsOption(S.string) |
| 426 | +
|
411 | 427 | "Hello World!"->S.parseOrThrow(schema) |
412 | 428 | // Some("Hello World!") |
413 | 429 | %raw(`null`)->S.parseOrThrow(schema) |
414 | 430 | // None |
415 | 431 | ``` |
416 | 432 |
|
417 | | -The `S.null` schema represents a data of a specific type that might be null. |
| 433 | +The `S.nullAsOption` schema represents a data of a specific type that might be null. |
418 | 434 |
|
419 | | -> 🧠 Since `S.null` transforms value into `option` type, you can use `Option.getOr`/`Option.getOrWith` for it as well. |
| 435 | +> 🧠 Since `S.nullAsOption` transforms value into `option` type, you can use `Option.getOr`/`Option.getOrWith` for it as well. |
420 | 436 |
|
421 | 437 | ### **`nullable`** |
422 | 438 |
|
@@ -907,7 +923,7 @@ The `S.list` schema represents an array of data of a specific type which is tran |
907 | 923 | ```rescript |
908 | 924 | let schema = S.unnest(S.schema(s => { |
909 | 925 | id: s.matches(S.string), |
910 | | - name: s.matches(S.null(S.string)), |
| 926 | + name: s.matches(S.nullAsOption(S.string)), |
911 | 927 | deleted: s.matches(S.bool), |
912 | 928 | })) |
913 | 929 |
|
@@ -1366,7 +1382,7 @@ And you can configure compiled function `typeValidation` with the following opti |
1366 | 1382 | `(S.t<'value>) => S.t<'value>` |
1367 | 1383 |
|
1368 | 1384 | ```rescript |
1369 | | -S.null(S.string)->S.reverse |
| 1385 | +S.nullAsOption(S.string)->S.reverse |
1370 | 1386 | // S.option(S.string) |
1371 | 1387 | ``` |
1372 | 1388 |
|
|
0 commit comments