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 2019 22:17
    CrossEye commented #2779
  • Jan 31 2019 21:04
    ArturAralin commented #2779
  • Jan 31 2019 20:08
    CrossEye commented #2779
  • Jan 31 2019 18:56
    buzzdecafe commented #2631
  • Jan 31 2019 18:09
    ArturAralin commented #2779
  • Jan 31 2019 16:18
    CrossEye commented #2779
  • Jan 31 2019 16:10
    CrossEye commented #2631
  • Jan 31 2019 16:06
    CrossEye commented #2777
  • Jan 31 2019 14:44
    ArturAralin opened #2779
  • Jan 31 2019 07:39
    inferusvv commented #2631
  • Jan 31 2019 03:07
    sespinozj commented #2771
  • Jan 31 2019 02:33
    machad0 commented #2771
  • Jan 31 2019 02:26
    JeffreyChan commented #2777
  • Jan 30 2019 14:30
    CrossEye closed #2777
  • Jan 30 2019 12:13
    vanyadymousky updated the wiki
  • Jan 30 2019 01:42
    JeffreyChan commented #2777
  • Jan 29 2019 21:06
    vanyadymousky updated the wiki
  • Jan 29 2019 16:28
    CrossEye commented #2777
  • Jan 29 2019 15:50
    mbostock commented #2772
  • Jan 29 2019 15:48
    CrossEye commented #2772
John Hartnup
@ukslim
Feedback very welcome.
kapilpipaliya
@kapilpipaliya
thanks for ramda
Lewis
@6ewis
R.isNil(a) || R.isNil(b)
Oskar Grunning
@sQVe
What would be the best way to write a signature for a object {k: v} but with a specfic design? It has the name Container in my TypeScript code but I'm a bit unsure how I should write the Hindley Milner signature.
combineContainers :: {k: v} -> {k: v} -> {k: v} seems a bit too generic - or am I wrong?
Brad Compton (he/him)
@Bradcomp
@6ewis any(isNil, [a, b])?
@sQVe is Container like a specific record type, or is it more like a typeclass?
Norbert
@norbertpy
Folks, what stops the 0.27.0 version to be published?
John Hartnup
@ukslim
@6ewis Why do you feel 'shortest' is a useful aim? And why mix Ramda and non-Ramda styles? or(isNil(a), isNil(b))
Mike Lambert
@lambert-velir
hey guys! I had a problem the other day, I needed to include all elements that had the field excluded set to true, but also all the elements that are before for after one that has excluded true
here's some sample data:
[
  {
    id: 1
  },
  {
    id: 2
  },
  {
    id: 3,
    excluded: true
  },
  {
    id: 4,
    excluded: true
  },
  {
    id: 5
  },
  {
    id: 6
  }
];
so the results should be 2, 3, 4, 5
I ended up using a regular [].reduce because I had an index, and could look at i -1 and i + 1
I was thinking about using R.aperture, but it doesn't quite do what I need
essentially, I need a filter that can look at the elements next to it
here's my solution:
array.reduce((acc, d, i) => {
  const excluded = d => d && d.exclude === true;

  if (excluded(d) || excluded(array[i - 1]) || excluded(array[i + 1])) {
    return acc.concat(d);
  }
  else {
    return acc;
  }
}, [])
John Hartnup
@ukslim
I'd be thinking about doing something slightly dirty with addIndex() and peeking into the original array.
Mike Lambert
@lambert-velir
yeah, similar to what I did above
Lewis
@6ewis

// given an arr of data objects, returns the field with the lowest minimum value
// i.e. which field has the lowest point on the graph: ['accumulatedDeposit', 'balance']?
export const getLowerMinimumOfFields = (data, fields) => {
  let lowest = { value: Infinity, type: '' };
  data.forEach((dateData) => {
    fields.forEach((field) => {
      if (dateData[field] < lowest.value) {
        lowest.value = dateData[field];
        lowest.type = field;
      }
    });
  });
  return lowest.type;
};
let's see the best ramda kungfu
@Bradcomp thank you
@ukslim it's not a aim - it's a bonus when it makes it more readble
// check if the lowest point is accumulatedDeposit or balance and use the lowest
  • field = field || getLowerMinimumOfFields(data, ['balance', 'accumulatedDeposit']);
John Hartnup
@ukslim
@6ewis Aha, OK. Shortness and readability often compete.
John Hartnup
@ukslim
@6ewis :
const data = [{ a: 1, b: 2, type: 'foo'}, {a: 2, b: 3, type: 'bar'}]
const fields = ['a', 'b'];
const lowestProp = pipe(props(fields), apply(min))
const lowestObj = reduce(minBy(lowestProp), { a: Infinity, type: 'init'});
const lowestObjType = pipe(lowestObj, prop('type'));

lowestObjType(data); // 'foo'
John Hartnup
@ukslim
Oops, lowestProp there only works for 2 properties.
Better: const lowestProp = pipe(props(fields), reduce(min, Infinity))
And actually you can do
const lowestObj = reduce(minBy(lowestProp), {});
John Hartnup
@ukslim
... if you don't mind lowestObjType([]) returning undefined, because min(0, undefined) is 0
John Hartnup
@ukslim
const data = [{ a: 1, b: 2, type: 'foo'}, {a: 2, b: 3, type: 'bar'}, {a: 2, b: 3, c: 0, type: 'baz'}]
const myFields = ['a', 'b', 'c'];
const lowestProp = fields => pipe(props(fields), reduce(min, Infinity))
const lowestObj = fields => reduce(minBy(lowestProp(fields)), {});
const lowestObjType = fields => pipe(lowestObj(fields), prop('type'));

lowestObjType(myFields)(data); // 'baz'

// or if it matters to you...
const lowestObjType2 = uncurryN(2, lowestObjType);
lowestObjType2(myFields, data); // 'baz'
Steven Duncan
@skuzbot
Could someone settle an ongoing discussion we've got going on in my office? How does one pronounce Ramda?
Brad Compton (he/him)
@Bradcomp
Ram duh
That's how I do it
Like Lambda but with an R
Steven Duncan
@skuzbot
awesome. Thanks!
Brad Compton (he/him)
@Bradcomp
What’s the alternative?
Steven Duncan
@skuzbot
I've heard (and occasionally said) ROM-dah
Konstantin Kostiuk
@SET001
have you guys encountered such a situation when your team refuses to use ramda just because "it`s hard to read" and "but we already have lodash"?
Ghost
@ghost~5e247c4ad73408ce4fd71e58
Hi guys, I checked out the "FP Patterns With Ramda" on educative.io and I'm wandering if anyone has ever made a custom functor. I implemented a functor for a tree (nested array) and I'm wondering if this is a public feature of Ramda. Docs don't say much and having to use { 'magical-land/map', value } looks weird.
Ben Briggs
@ben-eb
@o2genum_twitter Quite a few Ramda methods dispatch to obj[method], map is one of those. e.g:
const MyType = v => ({ map: f => MyType( f( v ) ) });

R.map( R.inc, MyType( 2 ) ) // MyType( 3 )
@SET001 Am in the process of trying to teach ramda style but it requires knowledge of a lot of different JS features. Things like currying and partial application are not easy concepts to understand at first
John Hartnup
@ukslim
@SET001 I think adopting Ramda in an existing team needs either a top-down authority figure saying "this is it", or a bunch of existing Functional Programming nerds.
It is very different from "normal" JS.
John Hartnup
@ukslim
@o2genum_twitter WRT custom functors etc. -- every time the Ramda docs say Dispatches to the xxx method of the xxx argument, if present., or similar, or also accepts fantasy-land compatible..., it's telling you what custom FP-friendly objects it can handle.
fantasy-land is a spec for FP-friendly types in JS. A fantasy-land compliant functor is defined here: https://github.com/fantasyland/fantasy-land#functor
If your tree object complies with fantasy-land, it'll work not only with Ramda, but with other JS FP libs that use the fantasy-land standard.
John Hartnup
@ukslim
@Bradcomp Note that the Ramda logo looks like a ram. It's pronounce ram-da; rhymes with "lambda" but with a "ram" replacing the "lamb".
msinton
@msinton
Hi, I'm attempting to write a simple script that uses ramda. But I'm getting stuck importing ramda - forgive my lack of knowledge. I want to essentially just run "node script.js" but it fails with
TypeError: Cannot read property 'fantasy-land/map' of undefined
Can I not do const R = require("ramda") and what do I do instead?
Brad Compton (he/him)
@Bradcomp
That sounds like you are trying to send in undefined as the second argument to map and nothing to do with imports
msinton
@msinton
@Bradcomp hmmm but the code works in Try-ramda
https://bit.ly/2NNkED7