Git Product home page Git Product logo

Comments (8)

engineforce avatar engineforce commented on May 10, 2024 1

Hi Vincent,

I have released 1.0.27, it includes a new function iassign.fp(), which is in functional programming friendly style, moved obj to the last parameter and supports currying. Please refer to example 8. Is that what you ask for?

from immutableassign.

crubier avatar crubier commented on May 10, 2024 1

Hi, thank you this is very nice.

However there is only one thing that could be made better: The order of argument could be changed in order to make this more useful: In the curried form, the options should be the first argument and not the last.

Also, to match lodash/fp, and as a matter of usability, it would be nice if it was autocurried, which means that we can call the function with any number of arguments, and it would be curried accordingly.

This would allow to write things like that

import iassign from "immutable-assign"
// We create our instance with no options
iassignFp = iassign.fp( undefined ) 

// ...

var nested1 = { a: { b: { c: [3, 4, 5] } } };

// ...

var mutation = iassignFp(
    (n, ctx) => (n.a.b.c[ctx.i])  ,
    (ci) => (ci + 100) ,
    {i: 1}
);

// ...

var nested2 = mutation(nested1);
// nested2 == { a: { b: { c: [3, 104, 5] } } }

I asked for this feature in your package, because otherwise I would have had to create a fork of your package just to implement this small change.

If you want I can code this and make a pull request. However you are really close right now

from immutableassign.

crubier avatar crubier commented on May 10, 2024 1

Hi, I just meant to move the option parameter first, not to reverse the argument order completely.

Auto currying is excellent !

from immutableassign.

crubier avatar crubier commented on May 10, 2024

It also allows to combine mutations using lodash/fp flowoperator, which creates new mutations... in a composable way !

newState = flow(
    mutate(
        state=>state.time,
        time=>time+1
    ),
    mutate(
        state=>state.score,
        score=>score*2
    )
)(currentState)

from immutableassign.

engineforce avatar engineforce commented on May 10, 2024

Hi Vincent,

Thanks for the advice, however your mutate function already works great, what do you want me to change in my library?

from immutableassign.

engineforce avatar engineforce commented on May 10, 2024

Hi Vincent,

Regarding iassign.fp(), do you want me to reverse the parameters order completely, e.g.,

iassign.fp = function <TObj, TProp, TContext>(    
    option: IIassignOption,
    context: TContext,
    setProp: setPropFunc<TProp>,
    getProp: getPropFunc<TObj, TProp, TContext>,
    obj: TObj): TObj; 

Or just move the option parameter to the first, e.g.,

iassign.fp = function <TObj, TProp, TContext>(
    option: IIassignOption,
    getProp: getPropFunc<TObj, TProp, TContext>,
    setProp: setPropFunc<TProp>,
    context?: TContext,
    obj?: TObj): TObj; 

In addition, it does support auto currying already in 1.0.27, i.e., you can call the function with any number of arguments.

from immutableassign.

engineforce avatar engineforce commented on May 10, 2024

Done in 1.0.28, please try and close the issue.

from immutableassign.

crubier avatar crubier commented on May 10, 2024

Nice, perfect thank you a lot !

from immutableassign.

Related Issues (20)

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.