These are chat archives for ramda/ramda

5th
Jul 2016
Emilio Srougo
@Emilios1995
Jul 05 2016 03:33
If someone wants to understand that better, the mostly adequate guide talks about it here
Now, can someone help me find an elegant point-free solution for this?
I want to get from here {number: '123', expiration: '06/18'}
to {number: '123', expiration_year: '18', expiration_month: '05'}
Emilio Srougo
@Emilios1995
Jul 05 2016 03:38
sorry, I mean expiration_month: '06'
Scott Christopher
@scott-christopher
Jul 05 2016 03:46
@Emilios1995 I don't know about elegant, but...
@ram-bot
const data = {number: '123', expiration: '06/18'};

converge(merge, [
  dissoc('expiration'),
  pipe(
    prop('expiration'),
    split('/'),
    apply(useWith(merge, [objOf('expiration_month'), objOf('expiration_year')]))
  )
])(data)
ram-bot
@ram-bot
Jul 05 2016 03:46
{ number: '123', expiration_month: '06', expiration_year: '18' }
Scott Christopher
@scott-christopher
Jul 05 2016 03:50

Actually, you can replace the

apply(useWith(merge, [objOf('expiration_month'), objOf('expiration_year')]))

with

zipObj(['expiration_month', 'expiration_year'])
@ram-bot
const data = {number: '123', expiration: '06/18'};

converge(merge, [
  dissoc('expiration'),
  pipe(
    prop('expiration'),
    split('/'),
    zipObj(['expiration_month', 'expiration_year'])
  )
])(data)
ram-bot
@ram-bot
Jul 05 2016 03:51
{ number: '123', expiration_month: '06', expiration_year: '18' }
Emilio Srougo
@Emilios1995
Jul 05 2016 03:58
@scott-christopher Thanks, TIL about converge!
Scott Christopher
@scott-christopher
Jul 05 2016 04:00
converge and useWith are those cheeky functions you typically turn to when playing point-free golf :D
Brad Compton (he/him)
@Bradcomp
Jul 05 2016 04:16

converge and useWith are those cheeky functions you typically turn to when playing point-free golf :D

Seconded! :laughing: They can also be the right tool for the job in some cases.

Tushar Mathur
@tusharmath
Jul 05 2016 13:32
How is ramdajs.com built?
Whats the build process?
What's the theme? How can one have a similar documentation ?
Christian Bongiorno
@chb0github
Jul 05 2016 16:02

I am trying to do a safe

require()

Where in, if the file doesn't exist, then require index.js. Using the node libraries for file checking make this trickier. Anyone wanna throw out some ideas? I can't use

defaultTo

because it doesn't take false and I was looking at fs.existsSync

Drew
@dtipson
Jul 05 2016 19:01
not sure if it was posted before, but this "Reducer Profunctor, Semigroup, BiContravariant Functor" implementation for state maniupulation is pretty nifty: https://jsfiddle.net/dmy01j1y/4/ Wish I could figure out who wrote it
Scott Christopher
@scott-christopher
Jul 05 2016 21:59
Texas Toland
@AppShipIt
Jul 05 2016 22:35
I don't see @paldepind's deepMerge in the docs did it go away?
Texas Toland
@AppShipIt
Jul 05 2016 22:49
Should've checked the example it appears to use set
Texas Toland
@AppShipIt
Jul 05 2016 23:00
It's doing something lens-like now I don't understand how to do deepMerge
andretshurotshka
@goodmind
Jul 05 2016 23:16
let getEntityFirstValue = curryN(2, (type, update) => {
  let match = getEntityFirst(type, update)
  return update.message.text.substr(match.offset, match.length)
})
how to write this point-free?
Scott Christopher
@scott-christopher
Jul 05 2016 23:34
@AppShipIt That R.set was short-lived and removed in #1181 and the name (for better or worse) was recycled for the current lens functionality.
You can still achieve something like a deepMerge with some recursive use of R.mergeWith.
@ram-bot
const deepMerge = mergeWith((a, b) =>
                            is(Object, a) && is(Object, b) ? deepMerge(a, b) : b)

deepMerge({ a: { b: { c: 'foo '}}, x: 'moo' }, { a: { b: { c: 'bar' }}, y: 'baa' })
ram-bot
@ram-bot
Jul 05 2016 23:36
{ a: { b: { c: 'bar' } }, x: 'moo', y: 'baa' }
Scott Christopher
@scott-christopher
Jul 05 2016 23:37
There is a slight caveat that it won't detect objects that were created using Object.create(null) though.
Not quite sure the best way to determine that one of those is an object.