diff --git a/typescript/option/src/helpers.ts b/typescript/option/src/helpers.ts index 2351ffc..bb455ad 100644 --- a/typescript/option/src/helpers.ts +++ b/typescript/option/src/helpers.ts @@ -90,6 +90,18 @@ export const withDefault = (_default: T, option: Option) => { return match(option, identity, always(_default)) } -export const flat = (option: Option>) => { - return bind(inner => (isSome(inner) ? flat(inner) : inner), option) +const checkIfOption = (x): x is Option => x[isOption] + +export const flat = (option: Option) => { + return match( + option, + inner => { + if (checkIfOption(inner)) { + return flat(inner) + } else { + return Some(inner) + } + }, + always(None) + ) }