Comments (8)
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.
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.
Hi, I just meant to move the option
parameter first, not to reverse the argument order completely.
Auto currying is excellent !
from immutableassign.
It also allows to combine mutations using lodash/fp flow
operator, 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.
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.
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.
Done in 1.0.28, please try and close the issue.
from immutableassign.
Nice, perfect thank you a lot !
from immutableassign.
Related Issues (20)
- Module "immutable-assign" has no default export. HOT 5
- Error when freeze and ignoreIfNoChange both true HOT 2
- iassign does not work correctly with ES6 Map HOT 2
- Error when using bracket notation to access property in getProp HOT 2
- Return the existing object when the value being set hasn't changed HOT 1
- Add a function to only freeze (if enabled) HOT 6
- How to handle possibly null values in getProp? HOT 5
- Proxy polyfill not applied on iOS 9.0 / Android 6.0 HOT 3
- typescript types for immutable-assign HOT 6
- Does not work with create-react-app HOT 1
- Unexpected behavior when Proxy === undefined HOT 2
- Feature request: Allow specifying the path of property to update by an array HOT 2
- How does this compare to immer? HOT 2
- Unexpected behaviour when console.log-ing or using lodash/fp/find HOT 3
- An in-range update of coveralls is breaking the build 🚨 HOT 1
- Support classes HOT 2
- ES6 arrow functions without the `return` keyword don't work as getProp HOT 2
- Provide initialization method HOT 2
- Cannot assign freeze property HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from immutableassign.