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)], [...], [...]]).
This thus returned me an Option<Option<number>>[][], and I want to "collapse" it to Option<number>[][] by merging the two options.
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.
What other, simpler way would there be to collapse like that?
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
Options, (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?