Skip to content

Commit d68e2be

Browse files
aspeddrozth
andauthored
Add Nullable.isNullable (#227)
* add `Nullable.isNullable` * update CHANGELOG.md --------- Co-authored-by: Gabriel Nordeborn <[email protected]>
1 parent a5ca1d5 commit d68e2be

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next version
44

5+
- Add `Nullable.isNullable` function. https://github.com/rescript-association/rescript-core/pull/227
56
- Remove some deps to Belt, Pervasives and Js. https://github.com/rescript-association/rescript-core/pull/226/commits
67

78
## 1.3.0

Diff for: src/Core__Nullable.res

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ external null: t<'a> = "#null"
77

88
external undefined: t<'a> = "#undefined"
99

10+
external isNullable: t<'a> => bool = "#is_nullable"
11+
1012
external make: 'a => t<'a> = "%identity"
1113

1214
external toOption: t<'a> => option<'a> = "#nullable_to_opt"

Diff for: src/Core__Nullable.resi

+21
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ Console.log(undefined) // Logs `undefined` to the console.
3838
*/
3939
external undefined: t<'a> = "#undefined"
4040

41+
/**
42+
`isNullable(a)` returns `true` if `a` is null or undefined, `false` otherwise.
43+
44+
## Examples
45+
46+
```rescript
47+
let myStr = "Hello"
48+
let asNullable = myStr->Nullable.make
49+
50+
// Can't do the below because we're now forced to check for nullability
51+
// myStr == asNullable
52+
53+
// Check if asNullable is not null or undefined
54+
switch asNullable->Nullable.isNullable {
55+
| true => assert(false)
56+
| false => assert(true)
57+
}
58+
```
59+
*/
60+
external isNullable: t<'a> => bool = "#is_nullable"
61+
4162
/**
4263
Creates a new nullable value from the provided value.
4364
This means the compiler will enforce null checks for the new value.

0 commit comments

Comments
 (0)