drboolean / immutable-ext Goto Github PK
View Code? Open in Web Editor NEWfantasyland extensions for immutablejs
License: ISC License
fantasyland extensions for immutablejs
License: ISC License
I have a DX question: should people import from immutable-ext
, or use it as a "polyfill" sort of?
index:
import 'immutable-ext';
import Application from './Application';
Application.start();
Application:
import Task from 'folktale/concurrency/task';
import { Map } from 'immutable';
Map({ thing: 'value' }).traverse(Task.of, x => Http.get(x))
Given the wide range of experience and variable value this adds based on what people work on (not everybody uses immutablejs
to the same extent in our applications), I feel like asking everybody to import List and Map from immutable-ext
, but the rest from immutablejs
might annoying to ask, and one of those nits during code review that are going to make me extremely disliked :D. Thoughts?
When I run npm i immutable-ext
Expected Behaviour
[email protected] /Users/amiterandole/Documents/current/javascript/composable-functional-javascript
└── [email protected]
Actual Behaviour
[email protected] /Users/amiterandole/Documents/current/javascript/composable-functional-javascript
├── UNMET PEER DEPENDENCY immutable@*
└── [email protected]
Currently I manually install immutable
first and then the install works
~/repos/sandbox/javascript/src [master] % node --trace-deprecation script.js
(node:59243) [DEP0128] DeprecationWarning: Invalid 'main' field in '/Users/onosendi/repos/sandbox/javascript/node_modules/immutable-ext/package.json' of 'dist/index.js'. Please either fix that or report it to the module author
at tryPackage (node:internal/modules/cjs/loader:364:15)
at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (/Users/onosendi/repos/sandbox/javascript/src/script.js:1:18)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
Currently the package listing doesn't link to the repo:
https://www.npmjs.com/package/immutable-ext
I'm presuming those links come from the package.json
fields?
https://docs.npmjs.com/files/package.json#repository
If all immutablejs types are extended from Collection
can't we just patch it with fantasy-land methods?
Hi there, first off thanks for this great little lib and all the videos!
I am running into a compilation error while trying to minify immutable-ext related code
Failed to minify the code from this file:
./node_modules/immutable-ext/index.js:2```
Here are the simple steps to reproduce it
npm i create-react-app
create-react-app demo2
cd demo2
yarn build
yarn add immutable immutable-ext
then add
import { List } from 'immutable-ext'
List(['Hey', 'Ho', 'Lets Go!'])
to index.js
yarn build
Cheers!
I've been very interested in using immutablejs in combination with a complete functional interface. I'm actually shocked to find this. I had searched a bunch and found like 1 or 2 weekend projects implementing immutablejs. How ready is this to be used? What should one's expectations be?
I tried to do: given a list of functions which return tasks, run given tasks sequentially, and return the task of a list of returned values.
For the following case, I expected to output: 1 2 3, but it outputted: 3 2 1.
const {task, of} = require('folktale/concurrency/task') // using folktale 2.x
const buildTask = (n, ms) => task(({resolve}) => setTimeout( ()=> {
console.log(n)
resolve(n)
}, ms
))
test('sequentially', async () => {
const {List} = require('immutable-ext')
await List.of(
() => buildTask(1, 500),
() => buildTask(2, 0),
() => buildTask(3, 1000)
)
.traverse(of, f => f())
.map(x=>x.toArray())
.run()
.promise()
})
if I change the following code, it gave me 1 2 3, which is what I expected.
List.prototype.traverse = function(point, f) {
return this.reduce((ys, x) =>
// f(x).map(x => y => y.concat([x])).ap(ys), point(this.empty))
ys.map(x => y => x.concat([y])).ap(f(x)), point(this.empty))
}
Not sure it is a issue, or by design.
It would be nice to be able to use this project with Typescript.
Is this something you would consider ?
Hello @DrBoolean,
I am a new-comer to FP and have watched all your videos to be able to start using it.
So currently we don't have access to index of element in List().traverse()
method. Can you add it?
Basically, from
List([1,2]).traverse(Task.of, (ele) => Task.of(ele))
to
List([1,2]).traverse(Task.of, (ele, index) => Task.of(ele))
workaround for now (but it may not be ideal for each situation):
List([1,2]).toMap().traverse(Task.of, (ele, index) => Task.of(ele))
So index becomes the key if we use toMap()
Also, you can take a look at other methods to make sure we have access to the index, if possible.
I hope it is something that is easy for you to implement.
Adding extra: false
to the first concat
argument generates type error, even when the same key is present on the second argument:
Map({name: "brian", age: Sum(30), extra: false})
.concat(
Map({name: "lonsdorf", age: Sum(30), extra: true})
),
Map({name: "brianlonsdorf", age: Sum(60), extra: true}))
generates
1) Maps concats the vals:
TypeError: prev.concat is not a function
at mergeWith (index.js:53:46)
at node_modules/immutable/dist/immutable.js:1956:52
at updateInDeepMap (node_modules/immutable/dist/immutable.js:1973:22)
at updateInDeepMap (node_modules/immutable/dist/immutable.js:1982:23)
at Map.updateIn (node_modules/immutable/dist/immutable.js:1280:26)
at Map.update (node_modules/immutable/dist/immutable.js:1272:14)
at node_modules/immutable/dist/immutable.js:1955:22
at node_modules/immutable/dist/immutable.js:1379:16
at ArrayMapNode.iterate.HashCollisionNode.iterate [as iterate] (node_modules/immutable/dist/immutable.js:1728:11)
at Map.__iterate (node_modules/immutable/dist/immutable.js:1377:32)
at Map.forEach (node_modules/immutable/dist/immutable.js:4383:19)
at node_modules/immutable/dist/immutable.js:1963:19
at Map.withMutations (node_modules/immutable/dist/immutable.js:1355:7)
at mergeIntoCollectionWith (node_modules/immutable/dist/immutable.js:1952:23)
at mergeIntoMapWith (node_modules/immutable/dist/immutable.js:1925:12)
at Map.mergeWith (node_modules/immutable/dist/immutable.js:1310:14)
at Map.concat (index.js:53:15)
at Context.it (test/test.js:24:10)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.