typescript(option): feat: added a "flat" helper
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
17569d9417
commit
c9cc0b0f22
2 changed files with 6 additions and 2 deletions
typescript/option/src
|
@ -1,7 +1,7 @@
|
|||
import { Option, Some, None } from './types'
|
||||
import { Binder, Folder, Mapper, Predicate, BackFolder } from './internalTypes'
|
||||
import { always, identity } from './internalHelperts'
|
||||
import Internals, { SomeClass } from './internals'
|
||||
import Internals, { SomeClass, isOption } from './internals'
|
||||
|
||||
export const isSome = <T>(option: Option<T>) =>
|
||||
option instanceof Internals.SomeClass
|
||||
|
@ -89,3 +89,7 @@ export const toNullable = <T>(option: Option<T>) => {
|
|||
export const withDefault = <T>(_default: T, option: Option<T>) => {
|
||||
return match(option, identity, always(_default))
|
||||
}
|
||||
|
||||
export const flat = <T>(option: Option<Option<T>>) => {
|
||||
return bind(inner => (isSome(inner) ? flat(inner) : inner), option)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue