typescript(option): refactor: islotated T | null in a Nullable internal type and updated the docs
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
6bd58b46ff
commit
689c746682
|
@ -194,7 +194,7 @@ A function to create options from nullable values.
|
||||||
### Signature
|
### Signature
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const fromNullable: <T>(value: T | null) => Option<T>
|
const fromNullable: <T>(value: Nullable<T>) => Option<T>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
import { Option, Some, None } from './types'
|
import { Option, Some, None } from './types'
|
||||||
import { Binder, Folder, Mapper, Predicate, BackFolder } from './internalTypes'
|
import {
|
||||||
|
Binder,
|
||||||
|
Folder,
|
||||||
|
Mapper,
|
||||||
|
Predicate,
|
||||||
|
BackFolder,
|
||||||
|
Nullable
|
||||||
|
} from './internalTypes'
|
||||||
import { always, identity } from './internalHelperts'
|
import { always, identity } from './internalHelperts'
|
||||||
import Internals, { SomeClass, isOption } from './internals'
|
import Internals, { SomeClass, isOption } from './internals'
|
||||||
|
|
||||||
|
@ -106,6 +113,6 @@ export const flat = <T, U>(option: Option<T>): Option<U> => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fromNullable = <T>(value: null | T): Option<T> => {
|
export const fromNullable = <T>(value: Nullable<T>): Option<T> => {
|
||||||
return value === null ? None : Some(value)
|
return value === null ? None : Some(value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,3 +5,4 @@ export type Binder<T, U> = Mapper<T, Option<U>>
|
||||||
export type Predicate<T> = Mapper<T, boolean>
|
export type Predicate<T> = Mapper<T, boolean>
|
||||||
export type Folder<T, U> = (s: U, v: T) => U
|
export type Folder<T, U> = (s: U, v: T) => U
|
||||||
export type BackFolder<T, U> = (v: T, s: U) => U
|
export type BackFolder<T, U> = (v: T, s: U) => U
|
||||||
|
export type Nullable<T> = T | null
|
||||||
|
|
Loading…
Reference in a new issue