Giter VIP home page Giter VIP logo

Comments (6)

paldepind avatar paldepind commented on May 24, 2024

Hello @joelnet. This is intentional but it should have been documented.

List's sort, sortBy and sortWith are not equivalent to Ramda's sorting functions. L.sortWith is the same as R.sort. L.sort only takes a single argument and that's why it appears to be non-curried.

The difference is intentional because I think List's approach is better than Ramda's. L.sort makes it very easy to sort a list of numbers or strings. And L.sortWith gives the same power that R.sort does.

I've considered opening an issue on Ramda about having Ramda adopt the same API.

I'd like to hear what you think about it all!

from list.

joelnet avatar joelnet commented on May 24, 2024

Ahh okay. So my confusion came in from the Implemented Ramda functions section, where sort is listed under implemented. My understanding of this was that it would be equivalent to ramda's sort function.

I went down this path because I am converting some ramda/array code to list. Most other changes went smoothly, but I got stuck on this one.

I wouldn't expect list and ramda to have identical interfaces, but the text sent me down the wrong path.

Changing sort to sortWith does work great, I did not consider using this because ramda has a different sortWith function.

Maybe just an asterisk with a footnote inside the Implemented Ramda functions section would be sufficient.

Thanks for your help!

from list.

paldepind avatar paldepind commented on May 24, 2024

I understand that. Thanks a lot for pointing out the problem. It's clearly not documented properly.

Would you be fine with the current situation as long as the docs are updated to properly explain it? To me the sort functions was a trade of between duplicating Ramda and having what I think is a better API. So I choose to diverge slightly from Ramda in that single case.

I went down this path because I am converting some ramda/array code to list. Most other changes went smoothly, but I got stuck on this one.

If you stumble upon some functions you need that are not implemented please open an issue and I'll do my best to get them implemented swiftly 😄

from list.

joelnet avatar joelnet commented on May 24, 2024

My situation was very specific, converting existing ramda code to list. If I had scrolled to the sort section I would have seen the interface, but I was only reading the Implemented Ramda functions to check the functions I needed to convert and swapping some R's for L's.

I don't think anything else has to change, I think list's implementation of sort is more intuitive (or what I would have expected) compared to ramda's.

I think just a small footnote in the Implemented Ramda functions would have caught my attention and would have been sufficient.

If you stumble upon some functions you need that are not implemented please open an issue and I'll do my best to get them implemented swiftly 😄

Unrelated, but since you brought up new functionality, I have some functions that will L.map and then Promise.all. This works great, but of course Promise.all returns an array and not a list. So I have some redundant code that looks like this:

const fn1 = pipeAsync(
  map(doAsync1),
  Promise.all, // appears at the end of multiple functions
  fromArray // appears at the end of multiple functions
)

const fn2 = pipeAsync(
  map(doAsync2),
  Promise.all, // appears at the end of multiple functions
  fromArray // appears at the end of multiple functions
)

I am considering either composing Promise.all and fromArray into a single function or creating a decorator like this:

import { list, fromArray } from 'list'

const promiseAwareDecorate = (func, value) =>
  value != null && typeof value.then === 'function'
    ? value.then(func)
    : func(value)

const withList = (func, context) => (...args) =>
  promiseAwareDecorate(fromArray, func.apply(context, args))

const promiseAll = withList(Promise.all, Promise)

const items = list(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))

promiseAll(items)
// => list(1, 2, 3)

Am I heading down the right path here or is there a tool in list that could help?

from list.

paldepind avatar paldepind commented on May 24, 2024

Thanks a lot for the feedback 😺

#48 should fix the documentation issue.

I have some functions that will L.map and then Promise.all. This works great, but of course Promise.all returns an array and not a list. So I have some redundant code that looks like this:

Good point! I definitely think that including something to ease that would be great. Promise.all is quite common.

The decorator looks interesting but I think that maybe a Promise.all composed with fromArray would be simpler? I'd be exactly like Promise.all except returning a list. What should such a function be called? all is already taken.

from list.

joelnet avatar joelnet commented on May 24, 2024

Ugg, I am terrible at naming things. When I start a new video game, I will spend 30 minutes staring blankly at the character creation screen!

The complexity of using function composition would be it has to be asynchronous like Ramda's pipeP. Though that might still be easier than a decorator. The decorator I created is also for sync and async functions. I think the merits of either are debatable.

Calling it all would be a conflict and something similar like allList might be compared to all and then confused as a boolean operation. Maybe a promiseAll. Though that would only handle Promise.all and not all functions that could return an array. I guess for those fromArray would suffice. I'm rambling now.

Sorry for stream of consciousness. Hopefully something in that was useful 😄

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.