Giter Site home page Giter Site logo

functional-js's People

Contributors

jakubbarczyk avatar leecrossley avatar njenan avatar r3oath avatar ryansroberts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar

functional-js's Issues

Currying increasing arity...

I like this and I'm thinking of using it in my next project but I'm struggling to understand why currying increases arity and whether this is a good idea. Is it taken from another functional language? The only one I am familiar with is Haskell which does not do that.

When I try currying a function with 3 inputs and then increasing the arity, I get strange results:

addAndMult = fjs.curry((x, y, z) => (x + y) * z
addAndMult (2, 6, 3)
24 // as expected: 8 times 3
addAndMult(2, 6, 3, 1)
0 // why?
addAndMult(2, 6, 3, 1, 2)
2 // why?
addAndMult(2, 6, 3, 1, 2, 3)
10 // why?

Curried function cannot be used in fold

I am attempting to fold a curried function across an array in the following way:

let curryGrow = fjs.curry(function grow(separator, acc, elem) {
  return acc + '' + elem + separator;
});
let growComma = curryGrow(',');
let result = fjs.fold(growComma, 'z')(['a', 'b', 'c']);

The final value of result in this case is the String '201000za,b,c,', while I would have expected the value to be 'za,b,c,'.

This can be worked around with an explicit function:

let grow = function(separator, acc, elem) {
  return acc + '' + elem + separator;
};
let growComma = function(acc, elem) {
  return grow(',', acc, elem);
};
let result = fjs.fold(growComma, 'z')(['a', 'b', 'c']);

Am I using the library correctly? I was attempting to do something the equivalent of in Haskell:

grow :: String -> String -> String -> String
grow separator acc n = acc ++ n ++ separator
foldl (grow ",") "z" ["a", "b", "c"]

The code used is just intended as a minimalist example, I do realise there are better ways to do it.

Edit: This is in Node.js 4.4.5

Replace fjs.isArray function

Array.isArray is native JavaScript and easy to read.

The isArray function is part of the Array.prototype object in ES2015

.each/.fold/.. on a NodeList

First of all, thank you for contributing this library, I find it nice and useful!

I ran into an issue trying to fold a NodeList. Consider this:

fjs.fold(function(data, field) {
    data[field.name] = field.value;
    return data;
}, {}, form.querySelector('[name]'));

This is failing silently, apparently because fjs.isArray returns false when given a NodeList. It might be a rash suggestion, but why not remove that check in fjs.each? Then (1) array-like structures (another example is function arguments) would be handled OK, and (2) some kind of error will be raised when trying to use a non-array (I would argue it is preferable not to let stuff like fjs.each(console.log, 42) go through without a complaint).

Feature suggestion - projection over dataset

Not an issue, but what do you think about including a "project" function to return a projection over a dataset, something like this:

projectAddress = project(["house", "street"]);
data = [{house: 24, street: "Main", name: "John"}, {house: 35, street: "Park", name: "Phil"}]
projectAddress(data)
// [ { house: 24, street: 'Main' }, { house: 35, street: 'Park' } ]

Here's a quick implementation:

projectOne = fields => obj => fields.reduce((x,y) => {x[y] = obj[y]; return x}, {})
project = fields => fjs.map(projectOne(fields))

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.