typescript(option): fix: fixed the flat helper returning a non-option value
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
c9cc0b0f22
commit
1fda9e8242
|
@ -90,6 +90,18 @@ export const withDefault = <T>(_default: T, option: Option<T>) => {
|
||||||
return match(option, identity, always(_default))
|
return match(option, identity, always(_default))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const flat = <T>(option: Option<Option<T>>) => {
|
const checkIfOption = <T>(x): x is Option<T> => x[isOption]
|
||||||
return bind(inner => (isSome(inner) ? flat(inner) : inner), option)
|
|
||||||
|
export const flat = <T>(option: Option<T>) => {
|
||||||
|
return match(
|
||||||
|
option,
|
||||||
|
inner => {
|
||||||
|
if (checkIfOption(inner)) {
|
||||||
|
return flat(inner)
|
||||||
|
} else {
|
||||||
|
return Some(inner)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
always(None)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue