Comments (4)
Hello @MonsieurMan. Thank you for the suggestion 😄
Here is one way you could do it with the current API.
const dots = L.map(generateDot, L.range(0, 50));
But, what you're describing sounds a lot like the Ramda function called times. With that function you'd do:
const dots = L.times(generateDot, 50);
The function is also passed the current index but obviously, it doesn't have to use it.
Am I correct that your generate
is the same as Ramda's times
? If so then I think we should add it with that name 😄
from list.
Yes, that's exactly it !
As for the name I don't know if you want to keep the exact same API as ramda, because I find repeatFunc
to be more readable and consistent with repeat
.
By the way I just wrote a first implementation like so:
export function repeatFunc<A>(func: () => A, times: number): List<A> {
let l = empty();
while(--times >= 0) {
l = append(func(), l);
}
return l;
}
I'm just not happy about the unit test I wrote which is quite dirty.
Would you like me to PR ? I'd like to contribute to the project, it seems fun and I think we maybe going to adopt it at my company.
from list.
I think I'd prefer to keep the same name as Ramda uses. I see your point with regards to repeatFunc
. But I also think the name "times" is ok. times
calls a given function a given number of times.
Would you like me to PR ? I'd like to contribute to the project, it seems fun and I think we maybe going to adopt it at my company.
I'd love a PR ❤️ Your implementation looks good! I think it should pass the current index like Ramda does. Passing the index certainly doesn't hurt. And if the type for func
is (index: number) => A
then it's still fine to give a function with no arguments.
In the documentation I think it would be nice to have a simple example like this one:
const l = times(n => n * n, 4); //=> list(0, 1, 4, 9)
And then also the example you gave to show that times
is useful to create a list with data generated by an impure function.
const dots = times(() => {
const x = Math.random() * width;
const y = Math.random() * height;
return { x, y };
}, 50);
Having good "realistic" examples like that is something that I think the documentation is currently lacking.
I'm just not happy about the unit test I wrote which is quite dirty.
You could do something like this maybe?
const l = times(n => n * n, 4);
assert.isTrue(equals(l, list(0, 1, 4, 9)));
Also, be aware that when you add a new function you also have to add it in the ramda file. Otherwise the tests will complain 😅
from list.
Here it is ! 😄
from list.
Related Issues (20)
- vindum.io link in README is broken HOT 1
- npm.js package is not linked to github repo HOT 4
- support sanctuary-show HOT 6
- groupWith seems broken HOT 6
- question: flatMap/chain and iterables HOT 3
- bugs: list returns wrong results (likely bug in drop function) HOT 12
- at least one other bug in the list HOT 19
- list throws HOT 5
- NonEmptyList HOT 7
- list will not release items for GC HOT 4
- What about `reduced`? HOT 7
- Reverse iteration HOT 10
- Stop mutating HOT 2
- multi-field sort HOT 8
- Can't find fromArray HOT 2
- .random possible? HOT 1
- head() is missing? HOT 3
- nth() throws when it's passed NaN HOT 2
- Access the index on map() operations HOT 4
- findLastIndex HOT 2
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 list.