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

fp-ts-extras

v4.2.0

Published

fp-ts extra functions and utilities

Readme

fp-ts extra functions and utilities

Array

groupBy

import { groupBy } from "fp-ts-extras/lib/Array";

assert.deepStrictEqual(groupBy(eqNumber)([1, 1, 2, 3, 3, 4]), [
  [1, 1],
  [2],
  [3, 3],
  [4],
]);

Option

partial

Drop-in replacement of t.partial

Instead of returning A | undefined, it returns Option<A>

import { partial } from "fp-ts-extras/lib/Option";

const B = partial({
  bar: t.number,
});
import * as t from "io-ts";

const User = t.type({
  userId: t.number,
  name: t.string,
});

const PartialUser = t.partial(User.props);

type PartialUser = t.TypeOf<typeof PartialUser>;

// same as
type PartialUser = {
  name: Option<string>;
  age: Option<number>;
};

Function

memPipe

Problem: I have a task and if I call

task();
task();

it fires the internal promise twice. The expected behaviour is it should only fire once. The second call returns the same result as the first one.

Use case: I have 3 tasks: t1, t2, t3. tA is called once t1 and t2 is done. tB is called once t1 and t3 is done. tC is called once t2 and t3 is done. With raw promise I could do

Promise.all([
   Promise.all([t1, t2]).then(_ => tA)
   Promise.all([t2, t3]).then(_ => tC)
   Promise.all([t1, t3]).then(_ => tB)
]).then(...)

But with Task

sequence([
   pipe(sequence([t1, t2])), chain(_ => tA)),
   pipe(sequence([t2, t3]), chain(_ => tC)),
   pipe(sequence([t1, t3]), chain(_ => tB)),
])
...

side effects of t1, t2, t3 will be fired twice each. memPipe will come in handy

import { memPipe } from "fp-ts-extras/lib/Function";

const t1 = memPipe(...)
const t2 = memPipe(...)
const t3 = memPipe(...)

sequence([
   pipe(sequence([t1, t2])), chain(_ => tA)),
   pipe(sequence([t2, t3]), chain(_ => tC)),
   pipe(sequence([t1, t3]), chain(_ => tB)),
])

Each task only performs side effect once.

JSON

encode/decode automatically when you stringify/parse

Why? You can use your preferred algebraic data types in your business logic, and can be converted to traditional json automatically when you do http request or save stuff to db, and vice versa.

const T = t.type({
  foo: optionFromNullable(t.string),
});

const result = stringify(T, {
  foo: O.of("abc"),
});
// right '{"foo":"abc"}'

const result = parse(T, '{"foo":"abc"}');
/*
right {
  foo: O.of("abc"),
}
*/

Record

union

import { union } from "fp-ts-extras/lib/Record";

assert.deepStrictEqual(
  union([
    {
      foo: "foo",
    },
    {
      bar: "bar",
    },
  ]),
  {
    foo: "foo",
    bar: "bar",
  }
);

String

import { split, join } from "fp-ts-extras/lib/String";
import { pipe } from "fp-ts/lib/Function";
import * as assert from "assert";

const result = pipe("a,b,c", split(","), join(":"));

assert.deepStrictEqual(result, "a:b:c");

TaskEither

decode

Decode with error to reduce boilerplate

import { decode } from "fp-ts-extras/lib/TaskEither";
import * as t from "io-ts";
import { pipe } from "fp-ts/lib/Function";

pipe(
  decode(t.string, null)
  // compose with other `TaskEither`s
);

Tuple

Various useful functions on tuples, overloaded on tuple size.

UUID

UUID generator that returns type UUID

Related projects

  • https://github.com/gcanti/fp-ts-contrib
  • https://github.com/samhh/fp-ts-std