These are chat archives for ramda/ramda

17th
Dec 2018
Jure
@jmav
Dec 17 2018 01:19

I have array of objects

const names = [
  {first:'Paul', last: 'Bel'},
  {first:'Tom', last: 'Dar'}
]

I would like to check if any of those fit object e.g {first:’Tom', last: ‘dar’} but would like to compare case insesitive Dar === dar

Jin
@Justin-ZS
Dec 17 2018 03:35
Hi, dose any use Ramda with TS? I'am new to typescript and meet a problem: "Type 'KeyValuePair<number, number>' is not assignable to type '[number, number]'"

the KeyValuePair is defined as

  interface KeyValuePair<K, V> extends Array<K | V> {
        0: K;
        1: V;
    }

I can't understand why...

Jin
@Justin-ZS
Dec 17 2018 03:53
OK, I fix it by asserting KeyValuePair<number, number> as [number, number]
Jure
@jmav
Dec 17 2018 10:49
From previous example I use R.any(R.whereEq({first:’Tom', last: ‘dar’}))(names)
how do I apply extra formating on item passed from any to whereEq?
I tride R.__ but returns error t something
Adam Szaraniec
@mimol91
Dec 17 2018 11:52
@jmav
const eqInsensitive = (a) =>(b) => String(a).toLowerCase() === String(b).toLowerCase()
const eqFn = (spec)=> map(eqInsensitive)
R.any(R.where(eqFn({first:'Tom', last: 'dar'})))(names)
Scott Sauyet
@CrossEye
Dec 17 2018 14:43

@jmav, @mimol91 : Note that there is a minor issue in that. It should be either

const eqFn = (spec) => map(eqInsensitive, spec)

or , probably better:

const eqFn = map(eqInsensitve)
I like that, though. I'd never thought of mapping over a spec object like that. If you only need it on some properties, it would look much uglier:
(R.where({first:equals('Tom'), last: eqInsensitive('dar')})
Ben Briggs
@ben-eb
Dec 17 2018 19:16
This is a nice read, although it's in ruby it would translate quite well to JS :) https://blog.conjur.org/special-cases-are-a-code-smell/
Scott Sauyet
@CrossEye
Dec 17 2018 19:26
You're right, a very nice read.
Julio Borja Barra
@juboba
Dec 17 2018 19:39
hey guys, do you know if there's something like flow that processes Hindley-Milner comments?
You might also like: https://github.com/xodio/hm-def
It isn't perfect, but handles most cases.
Julio Borja Barra
@juboba
Dec 17 2018 19:48
thanks man!
Rocky Madden
@rockymadden
Dec 17 2018 19:49
Sure. Re-reading your query I think the latter is what you might be after.
Jure
@jmav
Dec 17 2018 19:50
@CrossEye @mimol91 thx
Julio Borja Barra
@juboba
Dec 17 2018 19:51
@rockymadden yes. I think I can get used to that syntax for defining functions. I was wondering if there was something like flow that interpreted the signatures in comments previous to a function definition. But I will propose this one to the team.
Rocky Madden
@rockymadden
Dec 17 2018 20:01
Yeah, that would be super nice. It essentially is a wrapper around Sanctuary/Sanctuary-Def, if you look deeper. I am in the process of moving literally everything over. Dunno how I did it before. We even use to do some basic comments stuff, but people can too easily mess them up or have edge cases which violate.