Coder Social home page Coder Social logo

prelude's People

Contributors

briancavalier avatar davidchase avatar frangio avatar tylors avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

tylors

prelude's Issues

Why not using Ramda?

This would add some kb for sure, but the work there seems pretty solid and follows Fantasy Land. WDYT?

Consider changing compose & apply to accept a variable number of arguments

While attempting to use @most/prelude's compose function to make my own switchMap, like

import { map, switchLatest } from 'most'
import { compose } from '@most/prelude'
const switchMap = compose(switchLatest, map)

I ran into an error and realized it was because map needs to take in multiple arguments. I got around the problem by writing my own compose function in the library, like this:

const compose2 = (f, g) => (...args) => f(g(...args))
const switchMap = compose2(switchLatest, map)

And we could do the same with apply:

const apply = (f, ...args) => f(...args)

or maybe

const applyArray = (f, argsArr) => f(...argsArr)

I realize I could still accomplish the same things by using prelude's compose/apply + the curry functions, but it would require additional steps and would be less convenient.

We could also add partial application:

const partial = (f, ...args) => (...rest) => f(...args, ...rest)

And it might be more than what's wanted or is necessary for prelude, but we could go further by defining a fold1 to help create a variadic compose:

// like foldl1 in Haskell
const fold1 = (f, arr) => {
  if (!arr.length) {
    throw Error('fold1 must only be applied to non-empty lists')
  }

  let acc

  for (let i = 0; i < arr.length; i++) {
    acc = !acc ? arr[i] : f(acc, arr[i])
  }

  return acc
}

const compose2 = (f, g) => (...args) => f(g(...args))

// compose function for when the function arity is unknown
const compose = (...fs) => fold1(compose2, fs)

Thoughts on changing and/or adding any of these?

"module" field incorrectly exposes es6 syntax

The recent addition of the module field in #14 is not being used correctly.

The module field is suppose to point to code that "has ES2015 module syntax but otherwise only syntax features that browser/node supports." However the current module field points to the src folder - which still contains es6 features (e.g. let).

Maybe it would be better to also transpile the source to a lib folder where the code is all es5 expect for the es6 import/export syntax. Then that lib code could be exposed via the module field.

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.