We're a place where coders share, stay up-to-date and grow their careers.
Awesome! I sometimes use this trick to sequence foldables with different types:
function combineOption<A, B, C, D>(a: Option<A>, b: Option<B>, c: Option<C>, d: Option<D>): Option<[A, B, C, D]>; function combineOption<A, B, C>(a: Option<A>, b: Option<B>, c: Option<C>): Option<[A, B, C]>; function combineOption<A, B>(a: Option<A>, b: Option<B>): Option<[A, B]>; function combineOption<T>(...list: Array<Option<T>>): Option<T[]> { return array.sequence(option)(list); }
Isn't this just combineOptions = sequenceT(option)?
combineOptions = sequenceT(option)
Pretty much like it, yes. Although I should admit that sequenceT was introduced in fp-ts@2, while array.sequence works for fp-ts@1 as well.
sequenceT
array.sequence
Awesome! I sometimes use this trick to sequence foldables with different types:
Isn't this just
combineOptions = sequenceT(option)
?Pretty much like it, yes. Although I should admit that
sequenceT
was introduced in fp-ts@2, whilearray.sequence
works for fp-ts@1 as well.