typescript(option): feat: added a "flat" helper
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
17569d9417
commit
c9cc0b0f22
|
@ -16,7 +16,7 @@ npm install @adrielus/option
|
|||
|
||||
Curently there are no docs, but all functions have the same type definition as the ones from [fsharp](https://msdn.microsoft.com/en-us/visualfsharpdocs/conceptual/core.option-module-%5Bfsharp%5D) (except the ones from my package are not curreied)
|
||||
|
||||
There are also a few original helpers (match, and withDefault), but I'ts pretty easy to guess what those do
|
||||
There are also a few original helpers (match, flat and withDefault), but I'ts pretty easy to guess what those do
|
||||
|
||||
# Contributing
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue