npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

higher

v1.0.5

Published

Higher order functions for functional programming

Downloads

75

Readme

node-higher

Higher order functions for functional programming

Composition of ramda and lodash which both offer some similar but different features and paradigms and complementing features that need combining.

higher follows the paradigm of ramda in expecting the data on which to operate on is usually supplied last.

Installation

npm install higher --save

Use

const H = require('higher');
H.unless(_.isUndefined, 'test', test);

Functions

unless

What: Wrapper around ramda unless function that allows for values to be used instead of functions.

Why: Because writing () => { return 'some value'; } all the time is awful.

How: H.unless(_.isNull, 'test', value) (where _ is lodash) will return either value if it's not null or otherwise 'test' string.

ifElse

What: A concrete instance of ramda ifElse function that evaluates the given predicate or value and allows values to be used instead of functions.

Why: Because writing H.isFalsy('replacement value', maybeUndefined && maybeUndefined.someMethod()) all the time is lame and this makes the purpose clearer.

How: H.ifElse(maybeUndefined, MaybeUndefinedClass.someMethod, 'replacement value') (where _ is lodash) will return either 'replacement value or the result of MaybeUndefinedClass.someMethod applied on maybeUndefined.

ifFalsy

What: Wrapper around unless that tests the given value for falsy state.

Why: Because writing (x) => { return !!x; } all the time is tedious.

How: H.ifFalsy('FALSE', '') returns 'FALSE'

ifNull

What: Wrapper around unless that tests the given value for null value.

Why: Because writing unless(_.isNull, ... all the time is tedious.

How: H.ifNull('<null>', null) returns '<null>'

coerceFunction

What: Returns either the given function or function returning the given value.

Why: Because it's useful internally and maybe it will be useful externally.

How: H.coerceFunction(123) will return function returning 123

coerceArray

What: Returns either the given array or the given non-array value within an array.

Why: Because writing x = _.isArray(x) ? x : [x]; destroys neurons and I saw the example in Ramda documentation and loved it.

How: H.coerceArray(123) will return [123]

isNonEmptyString

What: Returns true if and only if the given value is a non-empty string (even if all the characters are whitespaces)

Why: Because writing _.String(value) && !_.isEmpty(value) is bound to make you zombie sooner or later (and I want to avoid it).

How: H.isNonEmptyString('') will return false whereas H.isNonEmptyString(' ') will return true

contains

What: Returns true if the given value is part of the given array.

Why: Because writing _.indexOf(array, value) !== -1 is way too long.

How: H.contains(['a', 'b'], 'c') will return false whereas H.isNonEmptyString(['a', 'b'], 'a') will return true

noopIfNotFunction

What: Returns _.noop if the given value is not a function thus guaranteeing that the returned value is always a function.

Why: Because writing callback = _.isFunction(callback) ? callback : _.noop has been written one too many times in the history of our Universe.

How: H.noopIfNotFunction(undefined) will return _.noop whereas H.noopIfNotFunction(() => undefined) will return () => undefined function.