Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next version

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

## 1.3.0
Expand Down
2 changes: 2 additions & 0 deletions src/Core__Nullable.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ external null: t<'a> = "#null"

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

external isNullable: t<'a> => bool = "#is_nullable"

external make: 'a => t<'a> = "%identity"

external toOption: t<'a> => option<'a> = "#nullable_to_opt"
Expand Down
21 changes: 21 additions & 0 deletions src/Core__Nullable.resi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ Console.log(undefined) // Logs `undefined` to the console.
*/
external undefined: t<'a> = "#undefined"

/**
`isNullable(a)` returns `true` if `a` is null or undefined, `false` otherwise.

## Examples

```rescript
let myStr = "Hello"
let asNullable = myStr->Nullable.make

// Can't do the below because we're now forced to check for nullability
// myStr == asNullable

// Check if asNullable is not null or undefined
switch asNullable->Nullable.isNullable {
| true => assert(false)
| false => assert(true)
}
```
*/
external isNullable: t<'a> => bool = "#is_nullable"

/**
Creates a new nullable value from the provided value.
This means the compiler will enforce null checks for the new value.
Expand Down