GithubHelp home page GithubHelp logo

hermann-p / pragmatic-fp-ts Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 0.0 3.74 MB

Oppinionated tools for functional programming in TypeScript. Usability before mathematical rigor.

JavaScript 1.20% TypeScript 98.78% Assembly 0.03%

pragmatic-fp-ts's People

Contributors

dependabot[bot] avatar hermann-p avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pragmatic-fp-ts's Issues

Create a minified bundle

Currently the lib exports some hundred individual small .js- and .d.ts-files. I would like to bundle them together into a single, minified .min.js file that can be used in node- and browser projects, while keeping type definitions to keep IDEs happy.

Flatten is very slow

This code has problems with large arrays:

import { getValueOr } from "./main";
const doFlatten = (elems: any): any[] =>
elems instanceof Array
? elems.reduce(
(accum: any[], elem: any) =>
elem instanceof Array
? [...accum, ...doFlatten(elem)]
: [...accum, elem],
[]
)
: elems;
export function flatten<A = any>(coll: any[]): A[] {
return doFlatten(getValueOr([], coll));
}

Reduce with spread is an anti-pattern because it implicitly makes nested iterations -> see https://www.richsnapp.com/article/2019/06-09-reduce-spread-anti-pattern which is very bad for performance.

Also it would be an advantage to distinguish between a single flatten and a recursive flatten function, like lodash does it with flatten and flattenDeep?

A more performant version of flatten/flattenDeep could be that one:

const doFlattenDeep = (elems: any): any[] =>
  elems instanceof Array
    ? elems.reduce((accum: any[], elem: any) => {
      elem instanceof Array ? accum.push(...doFlattenDeep(elem)) : accum.push(elem);
        return accum;
      }, [])
    : elems;

const doFlatten = (elems: any): any[] =>
  elems instanceof Array
    ? elems.reduce((accum: any[], elem: any) => {
      accum.push(elem);
        return accum;
      }, [])
    : elems;

function flattenDeep<A = any>(coll: any[]): A[] {
  return doFlattenDeep(l.getValueOr([], coll));
}

function flatten<A = any>(coll: any[]): A[] {
  return doFlatten(l.getValueOr([], coll));
}

These are the perf results with the new functions compared against lodash and the old one (nested array with 1000 entries):
flattenDeep is still slower than the lodash versions (but much faster than the old one), maybe because of not be an tail recursion?

image

Implement monadic futures

Currently using monads with promises can be a bit awkward. For this reason I'd like to implement monadic futures.

Todo:

  • research API and implementation details of well-working async- and future-monads
  • implement something that follows the spirit of the library

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.