Giter VIP home page Giter VIP logo

Comments (4)

paldepind avatar paldepind commented on May 25, 2024

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.

MonsieurMan avatar MonsieurMan commented on May 25, 2024

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.

paldepind avatar paldepind commented on May 25, 2024

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.

MonsieurMan avatar MonsieurMan commented on May 25, 2024

Here it is ! 😄

from list.

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.