Skip to content

_.flow does not preserve initial function arity #3612

@daedalus28

Description

@daedalus28

Using flow does not preserve the arity of the first function passed in, so _.curry won't work and you need to use _.curryN.

let add = (x, y) => x + y
let double = x => x * 2

// Returns 10
 _.flow(add, double)(1, 4)

// Throws Exception
_.curry(_.flow(add, double))(1)(4)

// Returns 10
_.curryN(2, _.flow(add, double))(1)(4)

More specifically this is 0:

_.flow(add, double).length

I've worked around this by defining a combo flow/curry function (forgive the silly name 😄 ):

let flurry = (...fns) => _.curryN(fns[0].length, _.flow(...fns))

This seems like a bug in _.flow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions