We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option<Option<T>>
Option<T>
Hello!
I was happily using this lib (great lib!), and I ran into a case where I ran a function that looks like this:
const addNullStartPadding = <T>( arr: T[][], extraRows: number, extraCols: number, ): Option<T>[][] =>
On a matrix that already contained Options, (e.g. const a = [[Some(1), None, Some(2)], [...], [...]]).
Option
const a = [[Some(1), None, Some(2)], [...], [...]]
This thus returned me an Option<Option<number>>[][], and I want to "collapse" it to Option<number>[][] by merging the two options.
Option<Option<number>>[][]
Option<number>[][]
I found that I could do:
const result: Option<Option<number>>[][] = ...; return result.map((row) => row.map((value) => value.andThen((v) => v)))
which is an effective way to do so, but I was expecting a more practical way to do this. Perhaps value.collapse(), or something.
value.collapse()
What other, simpler way would there be to collapse like that?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hello!
I was happily using this lib (great lib!), and I ran into a case where I ran a function that looks like this:
On a matrix that already contained
Option
s, (e.g.const a = [[Some(1), None, Some(2)], [...], [...]]
).This thus returned me an
Option<Option<number>>[][]
, and I want to "collapse" it toOption<number>[][]
by merging the two options.I found that I could do:
which is an effective way to do so, but I was expecting a more practical way to do this. Perhaps
value.collapse()
, or something.What other, simpler way would there be to collapse like that?
The text was updated successfully, but these errors were encountered: