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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ephetic/functional

v0.1.7

Published

ES6 functional helpers

Downloads

12

Readme

functional

Installation

yarn add @ephetic/functional

Erlang-inspired pattern matching

Patterns are checked in order, stopping with the first match. If no patterns match, the generated function will return undefined.

The pattern wildcard is the function itself (and can be aliased to any symbol you prefer).

Examples

import { matcher as m } from 'functional'

Match on constants or predicate functions

const isHi = m(['hi', true])

console.log(isHi('hi'))     // true
console.log(isHi('hello'))  // undefined

const fact = m(
  [1, 1],
  [m, n => n * fact(n-1)]
)

const fibo = m(
  [n => n <= 2, 1],
  [m, n => fibo(n-1) + fibo(n-2)]
)

Type/contract checking example

const t = (types, fn) => 
  process.env.NODE_ENV == 'production' 
  ? fn 
  : m([types, fn], 
      [m, (...args) => {throw `Type Check error: [${args}] doesn't match [${types}].`}])

const Integer = n => n === (n|0)
const addi = t([Integer, Integer], (a,b) => a + b)

const NonnegativeInteger = n => Integer(n) && n >= 0
const powish = t([Number, NonnegativeInteger], (b, e) => e > 0 ? b * pow(b, e - 1) : 1)
console.log(powish(2.2,3)) // works
console.log(powish(2,-3))  // throws

Match with RegExp

const isLikeHi = m([/.*hi.*/, s => `${s} is close enough`])

Match on argument types, values, and don't-cares

const secondIsNumber = m(
  [ [m, Number], (a,b) => console.log(`${b} is a Number`)],
  [ m,           (a,b) => console.log(`${b} is not a Number`)]
)

secondIsNumber('asdf', 2)   // 2 is a Number
secondIsNumber(2, 'asdf')   // asdf is not a Number

Note: since an array literal condition is used to represent the arguments list, to test against an actual array wrap it in a dummy object.

Match on given object shape

const isDuckman = m([{name: 'Duckman', age:40}, () => console.log('Duuuuckmaaaaan!')])
isDuckman({name: 'Duckman', age:40})  // Duuuuckmaaaaan!
isDuckman({name: 'Duckman'})          // undefined

const isDuckPerson = m([{name: m, age: m}, () => console.log('wubba lubba dub dub')])
isDuckPerson({name: 'Rick', age: 55}) // wubba lubba dub dub

Partial function application

Uses itself as wildcard to leave arbitrary parameters unbound.

import { partial as p } from 'functional'
const add = (a,b) => a + b
const div = (a,b) => a / b

const add1 = p(add, 1)
const halve = p(div, p, 2)