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

@typed/prelude

v6.0.0

Published

The TypeScript standard library

Downloads

15

Readme

@typed/prelude -- 5.0.0

The TypeScript standard library

Get it

yarn add @typed/prelude
# or
npm install --save @typed/prelude

API Documentation

All functions are curried!

Re-exported types and functions. Please see their respective documentation!


export {
  unpack,
  Either,
  Left,
  Right,
  isLeft,
  isRight,
  fromLeft,
  fromRight,
  mapLeft,
  chainLeft,
} from '@typed/either'
export {
  __,
  always,
  apply,
  compose,
  curry,
  curry2,
  curry3,
  curry4,
  curry5,
  curryN,
  flip,
  id,
  memoize,
  partial,
  pipe,
} from '@typed/functions'
export { composeLenses, lens, Lens, pipeLenses, updateAt, view } from '@typed/lenses'
export {
  append,
  arrayFrom,
  ascend,
  concat,
  contains,
  descend,
  drop,
  dropLast,
  endsWith,
  filter,
  find,
  findIndex,
  findLast,
  findLastIndex,
  flatten,
  forEach,
  groupBy,
  head,
  includes,
  indexOf,
  insert,
  isList,
  join,
  last,
  lastIndexOf,
  lensIndex,
  move,
  prepend,
  range,
  reduce,
  reduceRight,
  remove,
  reverse,
  slice,
  sort,
  splitAt,
  splitEvery,
  startsWith,
  take,
  takeLast,
  uniq,
  update,
  without,
} from '@typed/list'
export {
  all,
  allPass,
  and,
  any,
  anyPass,
  cond,
  equals,
  greaterThan,
  greaterThanOrEqual,
  ifElse,
  isArray,
  isIterable,
  isIterator,
  isMap,
  isNull,
  isNumber,
  isObject,
  isPromiseLike,
  isSet,
  isUndefined,
  lessThan,
  lessThanOrEqual,
  not,
  or,
  propEq,
  propOr,
  tryCatch,
} from '@typed/logic'
export {
  add,
  decrement,
  divide,
  increment,
  mean,
  median,
  modulo,
  multiply,
  negate,
  pow,
  product,
  subtract,
  sum,
} from '@typed/math'
export {
  fromJust,
  fromMaybe,
  isJust,
  isNothing,
  Just,
  Nothing,
  Maybe,
  combine,
  combineArray,
} from '@typed/maybe'
export {
  clone,
  hasOwnProperty,
  invoker,
  isEmpty,
  keys,
  length,
  lensPath,
  lensProp,
  path,
  prop,
  set,
  values,
} from '@typed/objects'
export { split, trim, toLowerCase, toUpperCase, substr, substring } from '@typed/strings'

ap<A, B>(fn: List<Arity1<A, B>>, values: List<A>): Array<B>

Apply the function contained in an Applicative to the values contained in another Applicative. Works with all data structures supported by chain and map.


export const ap: Ap = curry2(__ap)

function __ap<A, B>(fn: List<Arity1<A, B>>, value: List<A>): Array<B> {
  return chain((f: Arity1<A, B>) => map(f, value), fn)
}

export type Ap = {
  <A, B>(fn: List<Arity1<A, B>>, list: List<A>): Array<B>
  <A, B>(fn: Maybe<Arity1<A, B>>, maybe: Maybe<A>): Maybe<B>
  <A, B>(fn: PromiseLike<Arity1<A, B>>, promise: PromiseLike<A>): Promise<B>
  <A, B, C>(fn: Either<A, Arity1<B, C>>, either: Either<A, B>): Either<A, C>

  <A, B>(fn: List<Arity1<A, B>>): (list: List<A>) => Array<B>
  <A, B>(fn: Maybe<Arity1<A, B>>): (maybe: Maybe<A>) => Maybe<B>
  <A, B>(fn: PromiseLike<Arity1<A, B>>): (promise: PromiseLike<A>) => Promise<B>
  <A, B, C>(fn: Either<A, Arity1<B, C>>): (either: Either<A, B>) => Either<A, C>
}

chain<A, B>(f: (value: A) => List<B>, list: List<A>): Array<B>

Creates a new Monad from the value contained in another. Works with Maybe, Either, PromiseLike and List data structures.


export const chain: Chain = curry2<any, any, any>(function(f: (value: any) => any, list: any): any {
  if (isJust(list) || isNothing(list)) return maybeChain(f, list)
  if (isLeft(list) || isRight(list)) return eitherChain(f, list)
  if (isPromiseLike(list)) return Promise.resolve(list.then(f))

  return listChain(f, list)
})

export type Chain = {
  <A, B>(f: (value: A, index: number) => List<B>, list: List<A>): Array<B>

  <A, B>(f: (value: A) => Maybe<B>, maybe: Maybe<A>): Maybe<B>
  <A, B>(f: (value: A) => PromiseLike<B>, promise: PromiseLike<A>): Promise<B>
  <A, B, C>(f: (value: B) => Either<A, C>, either: Either<A, B>): Either<A, C>

  <A, B>(f: (value: A, index: number) => List<B>): (list: List<A>) => Array<B>
  <A, B>(f: (value: A) => Maybe<B>): (maybe: Maybe<A>) => Maybe<B>
  <A, B>(f: (value: A) => PromiseLike<B>): (promise: PromiseLike<A>) => Promise<B>
  <A, B, C>(f: (value: A) => Either<A, C>): (either: Either<A, B>) => Either<A, C>
}

map<A, B>(f: (value: A, index: number) => B, list: List<A>): Array<B>

Map over the value contained in a data structure. Works for List, Maybe, Either, and PromiseLike data strctures.


export const map: Map = curry2<any, any, any>(function map(f: (value: any) => any, list: any): any {
  if (isJust(list) || isNothing(list)) return maybeMap(f, list)
  if (isLeft(list) || isRight(list)) return eitherMap(f, list)
  if (isPromiseLike(list)) return Promise.resolve(list.then(f))

  return listMap(f, list)
})

export type Map = {
  <A, B>(f: (value: A, index: number) => B, list: List<A>): Array<B>
  <A, B>(f: (value: A) => B, maybe: Maybe<A>): Maybe<B>
  <A, B>(f: (value: A) => B, promise: PromiseLike<A>): Promise<B>
  <A, B, C>(f: (value: B) => C, either: Either<A, B>): Either<A, C>

  <A, B>(f: (value: A, index: number) => B): MapArity1<A, B>
}

export type MapArity1<A, B> = {
  (list: List<A>): Array<B>
  (maybe: Maybe<A>): Maybe<B>
  (promise: Promise<A>): Promise<B>
  <C>(either: Either<C, A>): Either<C, B>
}