Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 22:17
    CrossEye commented #2779
  • Jan 31 21:04
    ArturAralin commented #2779
  • Jan 31 20:08
    CrossEye commented #2779
  • Jan 31 18:56
    buzzdecafe commented #2631
  • Jan 31 18:09
    ArturAralin commented #2779
  • Jan 31 16:18
    CrossEye commented #2779
  • Jan 31 16:10
    CrossEye commented #2631
  • Jan 31 16:06
    CrossEye commented #2777
  • Jan 31 14:44
    ArturAralin opened #2779
  • Jan 31 07:39
    inferusvv commented #2631
  • Jan 31 03:07
    sespinozj commented #2771
  • Jan 31 02:33
    machad0 commented #2771
  • Jan 31 02:26
    JeffreyChan commented #2777
  • Jan 30 14:30
    CrossEye closed #2777
  • Jan 30 12:13
    vanyadymousky updated the wiki
  • Jan 30 01:42
    JeffreyChan commented #2777
  • Jan 29 21:06
    vanyadymousky updated the wiki
  • Jan 29 16:28
    CrossEye commented #2777
  • Jan 29 15:50
    mbostock commented #2772
  • Jan 29 15:48
    CrossEye commented #2772
coffeefedora
@coffeefedora
add23(); // ok invoke.
i mean, right now i'm doing var add23 = function() { return ff(2,3); };
but the ff func is a curried function, and i just kinda wondered if there was a pretty way. I am using this for effects, so I have a generic function I pre-bind values, so I can call it "toggleSaveButtons" vs "animate(element, startClass, endClass, ..)"
and maybe I should read the doc on R.partial right. I was invoking it wrong :(
heh
coffeefedora
@coffeefedora
running into a weird issue with using partial and jquery.
i'm trying to use partial like so:
const getInputs = r.partial(element.find, ['input']);
when invoked, jquery is throwing an error about pushStack not existing. i think the this object is somehow the culprit. any thoughts?
element is a jquery obj, and find is a method
coffeefedora
@coffeefedora
interesting, i can't even do this with normal js
var myfind = element.find; when i try to inovke gives same error
coffeefedora
@coffeefedora
and bind rears its head again. i'll never learn :)
mitcho
@mitchoSR_twitter
yeah easy
    const add = (a,b) => () => a + b;
    const add42 = add(4,2);
    console.log(add42()); //6
or in old es
    const add = function(a,b){
        return function(){
            return a + b;
        }
    }

    const add42 = add(4,2);
    console.log(add42()); //6
qwerty2712
@qwerty2712

Hi everybody! Can someone tell me how to convert an original array of objects to a new sorted array in Ramda.js and pure Javascript? Examples:

An original array of objects:

[
  {
    name: 'John',
    age: 37,
    posts: [
      { title: 'Ramda.js, part 1', date: '01.02.2019' },
      { title: 'Ramda.js, part 2', date: '02.02.2019' },
      { title: 'Ramda.js, part 3', date: '03.02.2019' }
    ]
  },
  {
    name: 'Bill',
    age: 25,
    posts: [{ title: 'Why Ramda?', date: '12.06.2019' }]
  },
  {
    name: 'Matthew',
    age: 21,
    posts: [{ title: 'Thinking in Ramda', date: '27.08.2019' }]
  }
]

A sorted array of objects (sort age in ascending order and date in descending order):

[ 
  {
    name: 'Matthew',
    age: 21,
    posts: [{ title: 'Thinking in Ramda', date: '27.08.2019' }]
  },
  {
    name: 'Bill',
    age: 25,
    posts: [{ title: 'Why Ramda?', date: '12.06.2019' }]
  },
  {
    name: 'John',
    age: 37,
    posts: [ 
      { title: 'Ramda.js, part 3', date: '03.02.2019' },
      { title: 'Ramda.js, part 2', date: '02.02.2019' },
      { title: 'Ramda.js, part 1', date: '01.02.2019' },
    ]
  },
]
Ben Briggs
@ben-eb
@coffeefedora Also there's thunkify(add)(2, 3)()
mitcho
@mitchoSR_twitter
@qwerty2712 something like
    const toUnix = d => new Date(d).getTime();

    const agesorter = R.sort((ua,ub) => ua.age < ub.age ? -1 : 1);
    const postsorter = R.sort((pa,pb) => toUnix(pa.date) > toUnix(pb.date) ? -1 : 1);

    let sorted = agesorter(data).map(u => {
      u.posts = postsorter(u.posts);
      return u;
    });
be careful with date syntax
qwerty2712
@qwerty2712
@mitchoSR_twitter Thanks for your quick answer! This helped me to understand some things.
mitcho
@mitchoSR_twitter
nw :)
makes me wonder if its possible to transduce while sorting
qwerty2712
@qwerty2712
Hm... I thought Ramda by default doesn't change source data. If you look at posts in the original array, you will see an ordered list like in sorted array. This is a normal behavior?
mitcho
@mitchoSR_twitter
i think i know what happened
qwerty2712
@qwerty2712
изображение.png
mitcho
@mitchoSR_twitter
it should be like this
  let sorted = agesorter(data).map(u => {
      let copy = {...u};
      copy.posts = postsorter(u.posts);
      return copy;
    });
my bad
wups
mitcho
@mitchoSR_twitter
also could do it like this which is pretty clean too
    const toUnix = d => new Date(d).getTime();
    const agesorter = R.sort((ua,ub) => ua.age < ub.age ? -1 : 1);
    const postsorter = R.sort((pa,pb) => toUnix(pa.date) > toUnix(pb.date) ? -1 : 1);
    let sorted = agesorter(data).map(u => Object.assign({}, u, {posts:postsorter(u.posts)}));
object assign is a bit foreign to some tho
Ben Briggs
@ben-eb
let sorted = agesorter(data).map(R.evolve({ posts: postsorter }))
mitcho
@mitchoSR_twitter
nice
Mike Austin
@mikeaustin

"[transducers] add a great deal of complexity to Ramda's implementations, and there has been some talk of removing them, or trying to find a way to make them optional. But not much has been done toward this."

https://stackoverflow.com/a/49735373

Mike Austin
@mikeaustin
Any truth to this or thoughts? I personally love them, as they solve a few different problems (pipelining, short-circuiting, composition).
1point7point4
@1point7point4
imo having a way to make them optional would be ideal
maybe you could have transducers in a separate library that extends ramda so people could still benefit, though that could cause some performance issues with programs designed for older versions of ramda
qwerty2712
@qwerty2712

How to sort object keys in Ramda? For example:

const { map, reduce, sort, keys, gt } = require('ramda')

// Unsorted array of objects
const arrayOfObjects = [
  {
    c: 5,
    a: 1,
    b: 3
  },
  {
    b: 3,
    c: 5,
    a: 1
  },
  {
    b: 3,
    a: 1,
    c: 5
  }
]

// Sorted array of objects (what I want):
const sortedArrayOfObjects = [
  {
    a: 1,
    b: 3,
    c: 5
  },
  {
    a: 1,
    b: 3,
    c: 5
  },
  {
    a: 1,
    b: 3,
    c: 5
  }
]

// My working code:
console.log(map(object => reduce((acc, key) => ((acc[key] = object[key]), acc), {}, sort(gt, keys(object))), arrayOfObjects))

Does anyone know how to make my code more readable?

Kurt Milam
@kurtmilam
@qwerty2712 https://bit.ly/33UC4nT :
const sortByKey = pipe(
  toPairs,
  sort(([k1], [k2]) => gt(k1, k2)),
  fromPairs
)

map(sortByKey)(data)
Kurt Milam
@kurtmilam
Your original code is easier for me to read when it's broken out over a few lines, e.g.:
map(
  object =>
    reduce(
      (acc, key) => (
        acc[key] = object[key],
        acc
      ),
      {},
      sort(gt, keys(object))
    )
)(data)
Kurt Milam
@kurtmilam
With reduce, I usually put each argument on a new line, especially if the reducer function is defined inline. When I use the sequence operator (the comma), I also usually put each step in the sequence on its own line, keeping in mind that it can be difficult to parse code that makes use of that operator.
These aren't hard and fast rules, for instance, I always put this on one line:
const log = x => (console.log(x), x)
qwerty2712
@qwerty2712
@kurtmilam thanks for your version of the code! I'll keep in mind your proposal about using line breaking in reduce.
Vlad Goldman
@ledniy
Hi everyone. Just started to play with Ramda, is there any way to made code prettier for those functions?
const applyIf = condition => condition ? myFunction : R.identity
const myFn = curry((a, b) => a + b) // more complex logic in real function

const evolveWith = data => R.evolve({
  field: myFn(R.prop('anotherField', data))
})(data)
Mike Austin
@mikeaustin
@1point7point4 I think it would be interesting to separate also, just to know when you're using transducers, and when you're not. Another question I've been asking myself is transducers via CPS vs transducers via generators. With generators, you can achieve (I believe) the same results, but all using iterators. I'm weary of all the GC created by iterators though, although some say this can be optimized away.
At the root of it, I was exploring the mechanics of transducers and notice Ramda's zip() just creates a plain array. zip can be made lazy by using generators/iterators, I'm curious why there's not lazy zip(). https://github.com/ramda/ramda/blob/master/source/zip.js
1point7point4
@1point7point4
what's cps (optimization noob here)
Brad Compton (he/him)
@Bradcomp
Continuation Passing Style (callbacks)