FxTS

A functional programming library for TypeScript/JavaScript

README

FxTS


FxTS is a functional library for TypeScript/JavaScript programmers.

Why FxTS?


- Lazy evaluation
- Handling concurrent requests
- Type inference
- Follow iteration protocols Iterable / AsyncIterable

Installation


  1. ```
  2. npm install @fxts/core
  3. ```

Documentation


Please review the API documentation

Usage


  1. ```ts
  2. import { each, filter, map, pipe, range, take } from "@fxts/core";

  3. pipe(
  4.   range(10),
  5.   map((a) => a + 10),
  6.   filter((a) => a % 2 === 0),
  7.   take(2),
  8.   each((a) => console.log(a)),
  9. );
  10. ```

Usage(concurrent)


  1. ```ts
  2. import { concurrent, countBy, flat, map, pipe, toAsync } from "@fxts/core";

  3. // maybe 1 seconds api
  4. const fetchWiki = (page: string) =>
  5.   fetch(`https://en.wikipedia.org/w/api.php?action=parse&page=${page}`);

  6. const countWords = async (concurrency = 1) =>
  7.   pipe(
  8.     ["html", "css", "javascript", "typescript"],
  9.     toAsync,
  10.     map(fetchWiki),
  11.     map((res) => res.text()),
  12.     map((words) => words.split(" ")),
  13.     flat,
  14.     concurrent(concurrency),
  15.     countBy((word) => word),
  16.   );

  17. await countWords(); // 4 seconds
  18. await countWords(2); // 2 seconds
  19. ```

you can start here

Build


- npm run build

Running Test


- npm test

Running Type Test


- npm run compile:check

License


Apache License 2.0