These are chat archives for ramda/ramda

12th
Apr 2018
Mike Lambert
@lax4mike
Apr 12 2018 00:15
what does padStart do?
Tomáš Konrády
@tommmyy
Apr 12 2018 08:43
Tomáš Konrády
@tommmyy
Apr 12 2018 08:57
@2upmedia your codereview is here https://goo.gl/Ccv6Kg
pdkn
@pdkn
Apr 12 2018 09:29
Thanks guys, My original approach was using String.prototype.padStart which worked fine locally but error'ed in CI environment so falling back to different approach. padLeft looks like what I need if I can add the Ramda extension else I'll dig deeper into why it's failing in CI env. Thanks again ;)
pdkn
@pdkn
Apr 12 2018 10:53
this works too (@via hivemind) const padStart = (str, padding, paddingCharacter) => ${join('', times(always(paddingCharacter), padding - length(str)))}${str}
padStart('23', 5, '0')
Tomáš Konrády
@tommmyy
Apr 12 2018 11:32
@pdkn or like that:
const padLeft = curry((l, pad, x) => until(o(lte(l), length), pad, x))

padLeft(10, '0')('1')
pdkn
@pdkn
Apr 12 2018 13:56
@tommmyy 👍
Mike Lambert
@lax4mike
Apr 12 2018 14:57
is there a way to use the first element as the seed to R.reduce?
or do i need to fallback to [].reduce?
but i guess that fails if the array is empty...
Brad Compton (he/him)
@Bradcomp
Apr 12 2018 15:08
converge(reduce(f), [head, tail])(arr)
Mike Lambert
@lax4mike
Apr 12 2018 15:08
ah, interesting
Frazer
@AlexFrazer
Apr 12 2018 15:09
gitter has really bad default settings
Brad Compton (he/him)
@Bradcomp
Apr 12 2018 15:09
This will indeed fail if the element has zero elements
Mike Lambert
@lax4mike
Apr 12 2018 15:09
right, maybe it's bad practice anyway
but it's a kind of annoying to create an empty/default object if your object is complex
Brad Compton (he/him)
@Bradcomp
Apr 12 2018 15:11
That's true. There are cases where you know that you'll have at least one item in the array
For Objects I'll usually use an empty object for my initial accumulator and use merge
sometimes, that visibility object is empty
so i had to provide the ["", 0] as the seed
Brad Compton (he/him)
@Bradcomp
Apr 12 2018 15:19
That looks pretty good to me
Pedr Browne
@Undistraction
Apr 12 2018 22:18
Is there a more compact way to apply a series of object values to a series of functions - the equivalent to something like this:
pipe(
  over(lensProp(`a`),  add(1)),
  over(lensProp(`b`), multiply(2)),
  over(lensProp(`c`), divide(2)),
)({a: 1, b: 2, c: 3) // => {a: 2, b: 4, c: 1.5}
Mike Lambert
@lax4mike
Apr 12 2018 22:18
maybe R.evolve
functionalStoic
@functionalStoic
Apr 12 2018 22:21
So I’m working with data coming from a csv file converting it to JSON. The csv has the headers which should be the keys for all of the body of the csv. The dilemma I’m running into is that there are 2 different fields that get repeated in the headers. I used PapaParse to do the conversion but it removes duplicate keys if I have the headers option turned on. I can turn that off and then the first element of my array of data is an array with the headers and the remaining elements are the data.
const headers = arr[0]
const body = tail(arr)
map(zipObj(headers), body)
Pedr Browne
@Undistraction
Apr 12 2018 22:21
@lax4mike That was the one. Thank you.
functionalStoic
@functionalStoic
Apr 12 2018 22:22
I get the same result if I use zipObj
Any ideas for how I should keep the duplicate keys intact and end up with a good structure?
Is ending up with something like my best option?
var myDataset = [ { "field_1": "lorem ipsum" }, { "field_2": 1 }, { "field_2": 2 }, { "field_2": 6 } ]
Mike Lambert
@lax4mike
Apr 12 2018 22:28
maybe
[ 
  { field: "field1", value: "lorem ipsum" },
  { field: "field2", value: 1 },
  { field: "field2", value: 2 }
]
this would be one row in your csv
functionalStoic
@functionalStoic
Apr 12 2018 22:36

ok that would work. I also thought about the non-unique fields being an array of objects. Something like

[
    {
        field1: value,
        field2: [
                          {field2: value},
                          {field2: value},
                          {field2: value}
                       ],
         field3: value
]

But I’m not really sure how to get it there

Mike Lambert
@lax4mike
Apr 12 2018 22:36
you can probably just do
field2: [ value, value, value ]
functionalStoic
@functionalStoic
Apr 12 2018 22:37
@lax4mike Well, the 2 fields that are duplicated are related to the same charge. Amount and Description of the charge