See the following code snippet:
const
  fun1 = () => Either.of(1),
  fun2 = () => Either.of(2),
  fun3 = () => Either.of(3),
  fun4 = curry((x, y, z) => Either.of(x + y + z)),
  fun5 = x => Either.of(x + 1),
  fun6 = () => pipeK(
    () => sequence(Either.of, [fun1(), fun2(), fun3()]),
    apply(fun4),
    fun5
  )(),
result = fun6() // returns 7
fun4 requires 3 arguments and I'd like to give them only if all of them are right arguments. That is, sequence will apply each monadic value so I'll get them as a single right containg the raw fun1, fun2, fun3 return values.
Is this the recommended approach?
                        
No, I would not use
sequencewith an array andapply. I think the more idiomatic approach is to useap:The equivalent in Haskell would be
fun5 =<< join (fun4 <$> fun1 <*> fun2 <*> fun3). Theunnestis needed whenfun4returns an Either, which might not be necessary.