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
Valerii Petryniak
@valerii15298
Doe anyone know how to move this to ramda? Will be very thankful:
          arr1.field1.forEach((item1) => {
            item1.arr2.forEach((item2) => {
              if (item2.neededFieldname === "value") {
                // here I found what I was searching for
                wantedEntity = item2;
              }
            });
          });
3 replies
Mike Lambert
@lax4mike
hey folks! I'm looking for some typescript help. How do I type a R.filter inside of a R.compose so that the next function in the composition knows the type?
4 replies
Ousama BELATAR
@bel3atar
  is there a more concise way to write this function ? `const build2WayLookupTable = mappings => R.mergeLeft(R.invertObj(mappings), mappings)`
wangzengdi
@adispring
@bel3atar Try the following two methods:
const build2WayLookupTable2 = R.chain(R.mergeLeft, R.invertObj);

const build2WayLookupTable3 = R.converge(R.mergeLeft, [R.invertObj, R.identity])
5 replies
Pierre-Yves Gérardy
@pygy
Hi folks, I'm about to be a bit off-topic here, is there a JS functional programming hub somewhere where I could pitch a library I wrote?
[pihentagy]
@pihentagy:matrix.org
[m]
Something like fp-ts? (it's typescript) https://discord.gg/HVWmBBXM8A
Pierre-Yves Gérardy
@pygy

@pihentagy:matrix.org Mmm, thanks! I'll have a look.

The lib is written in JS, but it has typings, which may benefit from people who know how to program with types.

Akira Cai
@blackwindforce
Pierre-Yves Gérardy
@pygy
Thanks @blackwindforce!
Pierre-Yves Gérardy
@pygy
@blackwindforce It looks like a private community. You can only sign in with an authorized account (either a pro email address or a Google/Apple account that the channel knows about). There's no way to sign up AFAICT
6 replies
Valerii Petryniak
@valerii15298

I have this function:

const extractEntities = (name: string) => ifElse(propEq(`${name}s`, {}), always([]), pathOr([], [`${name}s`, name]))

But as you see I am using arrow function, and as I had read in some articles about ramda usually when you write arrow function you can substitute by ramda function.
So is there any way to improve the function above??

4 replies
Tom Crisp
@crisptech
image.png
3 replies
hi all, does anyone have any good resources to suggest toward learning the ramda parameters notation? such as seen above
Scott Sauyet
@CrossEye
@crisptech: Sorry, not spending much time here anymore. But I wrote a long explanation at https://github.com/ramda/ramda/wiki/Type-Signatures
Alexei Kozhushkov
@joystick
Hi there, looking for a an idea how to transform input to output:
const input = [
  { id: 1, name: 'a', parentId: null },
  { id: 2, name: 'b', parentId: 1 },
  { id: 3, name: 'c', parentId: 4 },
  { id: 4, name: 'd', parentId: null },
  { id: 5, name: 'e', parentId: 2 },
]

const output = [
  { id: 1, name: 'a', items: [
    { id: 2, name: 'b', items: [
      { id: 5, name: 'e' }
    ]}
  ]},
  { id: 4, name: 'd', items: [
    { id: 3, name: 'c' }
  ]}
]
3 replies
D-Pro
@dmitry-prohorov

Hi guys! I'm very new to Ramda and taking hard time to get something done with it.
I need to transform input to output:

const input = {
    // ... lots of props,
    sections: [
        {
            heading: 'some header',
            layoutRows: [
                {
                    layoutItems: [
                        {
                            // ... lot of props,
                            editable: true,
                            label: 'item label',
                            layoutComponents: [
                                {
                                    // ... lot of props,
                                    label: 'component label',
                                    name: 'component name',
                                    type: 'Field'
                                }
                            ]
                        }
                    ]
                }
            ]
        }

    ]
}

const output =  [
    {
        header: 'some header',
        rows: [
            {
                label: 'item label',
                groupable: false,
                fields: ['component name1']
            },
            {
                label: 'item label',
                groupable: true,
                fields: ['component name1']
            }
        ]
    }
]

// mine ugly solution
const convertLayout = pipe(
    prop('sections'),
    map(
        ({heading: header, layoutRows}) => 
            ({
                header, 
                rows: pipe(
                    chain(prop('layoutItems')), 
                    filter(propEq('editable', true)), 
                    map(
                        ({label, layoutComponents}) => ({
                            label, 
                            groupable: layoutComponents.length > 1, 
                            fields: pipe(
                                filter(propEq('type', 'Field')), 
                                map(prop('name'))
                            )(layoutComponents) 
                        })
                    )
                )(layoutRows)
            })
    )
)
convertLayout(input)

My solution does not looks like something readable at all

2 replies
zhuijing
@zhuijing
汉兜弹幕版,https://b23.tv/BggRC8S
Abidh Muhammed
@abidhkm_gitlab

Hi
I am trying to convert an object to a nested structure
giving an example below:

input: { 'foo.bar': 'baz', 'foo.baz': 2, 'bar.foo': 1, 'bar.baz.0': 1, 'bar.baz.1': 2 baz: 3, }

output: { foo: { bar: 'baz', baz: 2, }, bar: { foo: 1, baz: [1,2] }, baz: 3, }
any reference for achieving this output?

Thanks

Akira Cai
@blackwindforce
Abidh Muhammed
@abidhkm_gitlab

@abidhkm_gitlab https://www.npmjs.com/package/flat

thank you, it helped

Adam Trager
@Nfinished
I'm having a ton of trouble typing this function if anyone has any input:
const findById = R.converge(
  R.find,
  [R.pipe(R.nthArg(1), R.propEq("id")), R.nthArg(0)]
);

findById([{ id: 1 }, { id: 2 }])(2) // {"id": 2}
findById([{ id: 1 }, { id: 2} ], 2) // {"id": 2}
zrn
@zrn:matrix.org
[m]

Can you verify that I did what I wanted? it looks like it works.

what I want at normalResult:
I want to multiply every element in array by 3

what I want at exitEarlyResult:
I want to multiply every element in array by 3 until I find element*3===6 at which point I want to stop computation and return false, if there are no elements like that then I want to return true

const transducer = map((x)=>{
  // console.log(`x is ${x}`) 
  return x*3
})

const iterator =  (acc, val) => acc.concat([val])

const initialValue = [];
const col          = [1,2,3,4,5]

const normalResult = transduce(transducer, iterator, initialValue, col)

const stop = (acc, val) => {
  // console.log(`acc ${JSON.stringify(acc)} val ${val}}`)
  return equals(6, val) ? reduced(false) : true
}

const exitEarlyResult = transduce(transducer, stop, initialValue, col)
1 reply
Tushar Mathur
@tusharmath
Is there a way to convert a function like A, A => B to A => B?
Essentially passing the same input twice?
1 reply
I need a higher order function that can do this.
something like — converge(identity, identity)?
is there a better way?
Matthias Seemann
@semmel
@tusharmath What is wrong with unnest :: (a→a→b)→a→b ?
[pihentagy]
@pihentagy:matrix.org
[m]

What is the simplest way to remove properties, which have null values?

So

const a = { hello: 'world', nobody: null };
const b = ??? ; //
b == { hello: 'world'};
2 replies
[pihentagy]
@pihentagy:matrix.org
[m]
Nice there is https://ramdajs.com/repl/ but what if I would like to show typescript snippet? Is there a platform, where I can load ramda and has ts support?
Daniel Power
@DanielPower_gitlab

Hi. I'm new to FP and Ramda. I'm using Typescript and running into a bit of a developer experience problem with pipe, and I'm wondering if there's a more elegant way to express what I'm writing.

  return pipe<
    [QuestLog],
    QuestLog,
    QuestLog,
    QuestLog,
    QuestLog,
    QuestLog,
    QuestLog,
    QuestLog,
    QuestLog
  >(
    createUser("dan"),
    createUser("rob"),
    createUser("estaban"),
    createUser("colin"),
    createUser("matt"),
    createCampaign(campaignUuid, "The Rainbow Sands", "matt"),
    addUserToCampaign(campaignUuid, "dan"),
    addUserToCampaign(campaignUuid, "rob"),
    addUserToCampaign(campaignUuid, "estaban"),
    addUserToCampaign(campaignUuid, "colin")
  )({
    campaigns: [],
    users: [],
  });

It seems that pipe cannot infer the types of my mutation functions, each of which are QuestLog -> QuestLog. To handle this, I have to write out a huge cluster of types in the template.

Is there either a way to have pipe infer the type appropriately, or a way to tell it that all arguments will be of the same type, so I only have to specify it once?

zrn
@zrn:matrix.org
[m]
I m not good at ramda but it seems you do many times same function just with new arguments, maybe just create a new function that would take an array of arguments and reduce it using your function?
zrn
@zrn:matrix.org
[m]
also you shouldn't mutate inputs if you do fp
Alexei Kozhushkov
@joystick

Hi there, i'm looking for a way to Ramda-mize the following:

const foo = ('someMethod', 'someParam') => x = > x.someMethod(someParam)

Much appreciated 🙃

3 replies
Tristan Forward
@tforward

This question is related to the Ramda Docs and Html sematics.

The Ramda Docs page has headers like "add", that when clicked navigate within the current window to the add function.

Looking at the html:

<h2>
<a tabindex="2" class="name" href="#add">add</a>
<span class="pull-right">
<span class="label label-category">Math</span>
<a target="_blank" title="View source on GitHub" href="https://github.com/ramda/ramda/tree/v0.28.0/source/add.js"><small class="glyphicon glyphicon-new-window"></small></a>
</span>
</h2>

Mdn docs for the a tag say using the ID creates the link,

<p><a href="#Section_further_down">
Jump to the heading below
</a></p>

<h2 id="Section_further_down">Section further down</h2>

Yet in Ramda docs there is no ID, so how does it still work?

zrn
@zrn:matrix.org
[m]
<div id="add" class="section-id"></div>
it is in fact there
but it's strange that h2 is not inside that div
Tristan Forward
@tforward
Thank you! Yeah that div is fairly odd. Not sure why the id and class are not just on the section tag itself vs. this ghost div element.
Justin Carrus
@jcarrus

Hi everyone, I'm new to Ramda (and FP) and was hoping for some help with implementing some code with Ramda.

I have an object o with current value of { foo: [{ value: "bar" }] }.

I would like to create a function that appends an array of newData to one of the child arrays of existingData based on a dynamic criteria (in this case, I just take the first key of existingData).

Without Ramda, it looks like this:

const o = { foo: [{ value: "bar" }] };
function pushToFirstKey(newData, existingData) {
  const key = Object.keys(existingData)[0]
  return {
    ...existingData,
    [key]: [...existingData[key], ...newData]
  }
}
pushToFirstKey([{ value: "baz" }], o);
// Result: {"foo": [{"value": "bar"}, {"value": "baz"}]}

link

My attempt with Ramda looks like this:

const o = { foo: [{ value: "bar" }] };
const pushToFirstKeyFP = (newData, existingData) =>
  R.compose(
    R.assocPath([R.head(R.keys(existingData))], R.__, existingData),
    R.concat(R.prop(R.head(R.keys(existingData)), existingData))
  )(newData);
pushToFirstKeyFP([{ value: "baz" }], o);
// Result: {"foo": [{"value": "bar"}, {"value": "baz"}]}

link

Which I suspect could be better written.

Does anyone have suggestions for me?

zrn
@zrn:matrix.org
[m]
it is kind of strange that you named parameters somethingData, when first is shape of [{}] and second is a different shape {[{}]}.
you can use modify like this:
const mergeArraysAtFirstKey = (arr, obj) => (
  modify(head(keys(obj)),
         concat(arr))
);
also make sure that you actually know what first key will be, if there are keys that could be converted to number then they would be first
Justin Carrus
@jcarrus
@zrn:matrix.org ahh, thanks! That is much cleaner! And yes, good point on my naming. This was really helpful
zrn
@zrn:matrix.org
[m]

I should have mentioned that this is just for illustration, I wanted to understand how exactly it works, so optimisations like that wouldn't work in my case.

I also didn't hope to get any answer after so long, since then for my case I also considered generators, but they have overhead and are slower when entire collection must be computed. What is the performance price of using transducers? They look a bit like generators, object that has a function. So I guess it could be same as generators.

zrn
@zrn:matrix.org
[m]
I think I made a different design so I don't need to solve exactly this problem, still I hope I understood right how transducers work. But I want to know how they perform and when should they be used and when they should not be used.
The Very Angry Caterpillar
@ti_estin_twitter

I don't know if this is useful information, but I found an example where R.flatten() on an array of objects with a length property does not work as intended.

https://ramdajs.com/repl/?v=0.28.0#?const%20obj%20%3D%20%7B%20length%3A%200%20%7D%0Aconst%20array1%20%3D%20%5B%20obj%2C%20obj%2C%20obj%20%5D%0Aconst%20array2%20%3D%20%5B%20array1%2C%20array1%2C%20%5B%20array1%2C%20array1%20%5D%2C%20array1%2C%20array1%5D%0A%0Aconsole.log%28R.flatten%28array2%29%29%0Aconsole.log%28array2.flat%282%29%29

In this example, R.flatten(array) and array.flat() produce different results.
This behavior is probably due to the fact that in the implementation of _isArrayLike(), an object with a length property of 0 is considered an array.
(I found this while using CodeMirror; CodeMirror's Line object has a length property which signifies how many chars the Line has.)

zrn
@zrn:matrix.org
[m]
idk if ramda should do exactly as normal js methods, map doesn't work exactly like method because of index parameter.
if (x.length === 0) { return true; } there is specific case for such object which makes it array like so I guess it works as intended.
I think it makes sense, we have {0: 'a', length: 1} this is array like, same "array" with zero items should look like {length: 0}