镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Add _.withDefault combinator #166

Description

@joshuacc

The _.withDefault function would accept a function as its argument, and returns a new function that transparently replaces null/undefined return values with a default value.

Example:

function getArrLength (arr) {
  if (_.isArray(arr)) return arr.length;
}

getArrLengthOrZero = _.withDefault(getArrLength, 0);

getArrLengthOrZero({});
// => 0

May need a better name for the function, though.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

after modulesThis should be postponed until after modularization (temporary label, see #220)enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions