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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@algosail/pair

v0.1.0

Published

Small collection of FP utilities for working with pairs.

Readme

@algosail/pair

Ordered 2-tuple (pair) utilities. Pairs are plain two-element JavaScript arrays [a, b].

Contents


pair

pair :: a -> b -> [a, b]

Constructs a 2-element tuple.

pair(1)(2) // => [1, 2]
pair('key')('val') // => ['key', 'val']
pair(true)(null) // => [true, null]

dup

dup :: a -> [a, a]

Duplicates a value into a pair.

dup(3) // => [3, 3]
dup('hi') // => ['hi', 'hi']
dup([1, 2]) // => [[1, 2], [1, 2]]

fst / snd

fst :: [a, b] -> a
snd :: [a, b] -> b

Extract the first or second element.

fst([1, 2]) // => 1
snd([1, 2]) // => 2

// Useful in pipelines
const pairs = [
  [1, 'a'],
  [2, 'b'],
  [3, 'c'],
]
pairs.map(fst) // => [1, 2, 3]
pairs.map(snd) // => ['a', 'b', 'c']

merge / mergeSecond

merge       :: [(a -> b), a] -> b
mergeSecond :: [a, (a -> b)] -> b

Apply the function element of a pair to the value element.

merge([(x) => x + 1, 5]) // => 6
merge([(s) => s.toUpperCase(), 'hello']) // => 'HELLO'

mergeSecond([5, (x) => x + 1]) // => 6
mergeSecond(['hello', (s) => s.length]) // => 5

swap

swap :: [a, b] -> [b, a]

Swaps the two elements.

swap([1, 2]) // => [2, 1]
swap(['key', 'val']) // => ['val', 'key']

map

map :: (a -> c) -> [a, b] -> [c, b]

Maps over the first element, leaving the second unchanged.

map((x) => x + 1)([1, 'x']) // => [2, 'x']
map((s) => s.length)(['hi', 0]) // => [2, 0]

mapSecond

mapSecond :: (b -> d) -> [a, b] -> [a, d]

Maps over the second element, leaving the first unchanged.

mapSecond((x) => x * 2)([1, 5]) // => [1, 10]
mapSecond((s) => s.trim())(['k', '  v  ']) // => ['k', 'v']

bimap

bimap :: (a -> c) -> (b -> d) -> [a, b] -> [c, d]

Maps both elements simultaneously.

bimap((x) => x + 1)((x) => x * 2)([1, 3]) // => [2, 6]
bimap(String)(Boolean)([42, 0]) // => ['42', false]

fold

fold :: ((c, a, b) -> c) -> c -> [a, b] -> c

Reduces a pair with a ternary function f(initial, first, second).

fold((acc, a, b) => acc + a + b)(0)([3, 4]) // => 7
fold((_, a, b) => a * b)(0)([3, 4]) // => 12
fold((s, k, v) => `${s}${k}=${v}`)('')(['x', 42]) // => 'x=42'

foldWith

foldWith :: (a -> b -> c) -> [a, b] -> c

Applies a curried binary function to both elements.

foldWith((a) => (b) => a + b)([1, 2]) // => 3
foldWith((a) => (b) => [a, b])([1, 2]) // => [1, 2]  (round-trip)
foldWith(pair)([1, 2]) // => [1, 2]   (same)

traverse

traverse :: (b -> f b) -> (f (a->b) -> f a -> f b) -> ((a->b) -> f a -> f b) -> (a -> f b) -> [a, c] -> f [b, c]

Applicative traversal over the first element. The second element is preserved.

// Traverse with Maybe
traverse(just)((mf) => (ma) => ap(mf)(ma))((f) => (ma) => map(f)(ma))((x) =>
  x > 0 ? just(x * 2) : nothing(),
)([3, 'tag']) // => just([6, 'tag'])

traverse(just)((mf) => (ma) => ap(mf)(ma))((f) => (ma) => map(f)(ma))((x) =>
  x > 0 ? just(x * 2) : nothing(),
)([-1, 'tag']) // => nothing()