DEV Community

loading...

Discussion on: fp-ts, sequenceT, and sweet sweet async typed FP

Collapse
ybogomolov profile image
Yuriy Bogomolov

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);
}
Collapse
giogonzo profile image
Giovanni Gonzaga

Isn't this just combineOptions = sequenceT(option)?

Collapse
ybogomolov profile image
Yuriy Bogomolov

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.