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
D
@keeoth_gitlab

I'm sure a number of you may have already heard but there is a new ECMAScript proposal for "Types as Comments". It's basically a way to allow TypeScript and Flow code to run in the browser as is. It's just Stage 0 and might get shelved before ever making it somewhere but the interesting thing is that it's being pushed by representatives from Microsoft and it already has some heavy hitters from the ECMAScript proposal community engaging with it. As we all know, using TS for functional programming has some frustrating limitations and hoops to jump through. So I just want to make sure the functional JS is community aware of the proposal and encourage people to go explore the proposal and speak up so we're represented in the discussion.

Thanks!

https://github.com/giltayar/proposal-types-as-comments

talhaguy
@talhaguy
Does Ramda have a function that maps array values as arguments to an array of functions? Eg I'm looking for: [1, 2], [fn1, fn2] to be fn1(1) and fn(2). I made it myself but curious if there's a built in function for this.
5 replies
zrn
@zrn:matrix.org
[m]

is there something like until but returning array of all values instead of last one?
like in example

R.until(R.gt(R.__, 100), R.multiply(2))(1) // => 128

it would return [1,2,4,8,16,32,64,128]

zrn
@zrn:matrix.org
[m]

ok I found unfold

const f = n => n > 100 ? false : [n, n * 2];
R.unfold(f, 1); // =>[1,2,4,8,16,32,64]

```

talhaguy
@talhaguy
What is the idiomatic way in Ramda to bring along temporary variables that need to be used later in piped functions? E.g. let's say I have 2 functions in a pipe. A param is given to the first function and produces a result. This result is piped to the 2nd function. However I need the original param as well in this function. Right now I've been accumulating either an object or an array with the temporary calculations or variables I might need and it works, however I was looking for a potentially better way. Thanks!
wangzengdi
@adispring
@talhaguy You can use R.converge with R.identity, or R.chain, or R.ap
wangzengdi
@adispring
Function can be regard as Reader Monad, which can be used to pass the same param to multiple procedure.
talhaguy
@talhaguy
@adispring - Thank you! Side note, I came across a nice clean way to do it in fp-ts (https://gcanti.github.io/fp-ts/guides/do-notation.html) which seems to follow the do notation from Haskell. Will try what you suggested in Ramda.
gpindia
@gpindia:matrix.org
[m]
:point_up: Edit: Also, I have doubt if ramda functions can cause environment related issues because I am facing this issue on a particular environment, otherwise it works fine. Can anyone help what can cause this?
Marcus Blättermann
@essenmitsosse

I had a look at https://github.com/ramda/ramda.github.io and was actually wondering, if there is some kind of build process involved, that just pushes to the repo, or if for new versions, someone just copies the folder and edits everything by hand. Would love to contribute to the docs, but wanted some understanding beforehand.

(hope this is the right channel for this)

wangzengdi
@adispring
@essenmitsosse ramda generate its document website automatically based on ramda/ramda repo.
JoeIsCool
@JoeIsCool
Hi, can you use transducers with functions like groupBy and CollectBy?
Charles Hughes
@chughes87
Anyone know good companies/teams in SF bay area that use Ramda? I am looking for a job. 8 years JS exp split pretty even btw frontend and backend.
Valerii Petryniak
@valerii15298
Hello, guys. @essenmitsosse @adispring . I was trying to use autocompletion for R.omit but appears there is no one) what do you think about this typing of omit instead of current one: export function omit<T extends object, K extends keyof T>(names: readonly K[], obj: T): Omit<T, K>;
1 reply
T extends object prevents to pass something else, bcs now it allows to pass anything. And K extends keyof T allows to narrow types and gives us nice autocompletion.
James Howe
@jhoweaa

Is there a way to handle HTTP errors that happen when using the declarative HTTP Client? For example, I have defined a client interface with this method:

Publisher<DetailsResponse> getDetails(@Header(AuthConstants.AUTH_TOKEN_HEADER) String authToken,
                                                                                    @Body DetailsRequest request);

Elsewhere in a controller, I use the client to resolve a request:

  public Publisher<DetailsResponse> mappings(@Body DetailsRequest detailsRequest , Authentication authentication) {
    //if (1 == 1) throw new HttpClientResponseException("Error", HttpResponse.badRequest());

    String authToken = (String) authentication.getAttributes().getOrDefault("authToken", "");
    return myClient.getDetails(authToken, detailsRequest );
}

If the client returns a 200, everything works fine. However, if the client encounters an exception, perhaps the server returned a 500, I would like to be able to handle the error myself and return a response of my choice.

I've defined an HttpClientResponseExceptionHandler, which works if the error occurs in my Controller code (see the commented out line that I used as a test), however, if the exception happens in the declarative client, my handler is never invoked. In that case, the error is thrown in the DefaultHttpClient code.

I'm sure if I used the low-level HttpClient I could handle this, but I was wondering if I'm missing some trick when using the declarative client? This is using the 3.4.2 version of Micronaut.

Thanks!

GandhiVir
@GandhiVir

Hi, I am still kinda new to Ramda, and I am facing some trouble figuring out the right way to create the function.
Hope someone can help me here.

I have a list of list which is grouped by key = a

[
   [{ a: 1, b1: 1}],
   [{ a: 2, b2: 2}, { a: 2, b2: 3, c2: 2}],
   [{ a: 3, b3: 3}, { a: 3, c3: 5}]
]

Each item in the outer list contains only one or two elements.
Now my goal is - if it contains 2 elements I want to do mergeRight, and if it's just one element I want to keep it as it is.

I was thinking I can map over the outer list and do R.mergeRight(R.nth(0), R.defaultTo({}, R.nth(1))). So basically R.map(R.mergeRight(R.nth(0), R.defaultTo({}, R.nth(1))))(list).
However, I am not able to make it work. My guess is the item is not being passed to R.nth function.
Can anyone help me figure out the problem?

6 replies
wangzengdi
@adispring
@GandhiVir
const list = [
   [{ a: 1, b1: 1}],
   [{ a: 2, b2: 2}, { a: 2, b2: 3, c2: 2}],
   [{ a: 3, b3: 3}, { a: 3, c3: 5}]
]

const mergeRightIfNeeded = R.map(
  R.when(
    R.propEq('length', 2),
    R.apply(R.mergeRight)
  )
)

const result = mergeRightIfNeeded(list)

console.log(result);
7 replies
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)
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?