These are chat archives for ramda/ramda

25th
Apr 2017
Just RAG
@justrag
Apr 25 2017 09:58
Remove all the elements which equal 3 from the array:
R.reject(R.equals(3))(myList);
Is there a better way?
Mick Dekkers
@mickdekkers
Apr 25 2017 10:37
How can I make this pointfree?
const doohickey = (fn, keys) => R.pipe(
  R.map(R.objOf(R.__, fn)),
  R.mergeAll
)(keys)
Denis Stoyanov
@xgrommx
Apr 25 2017 10:39
why do u want PF style?
Mick Dekkers
@mickdekkers
Apr 25 2017 10:39
In this case mostly because I want to see if it's possible
converge usually works for me but I'm not sure if that could be applied here given that some of the arguments are used inside R.objOf which is inside R.map
Tushar Mathur
@tusharmath
Apr 25 2017 10:47
@SoullessWaffle
const doohickey = R.pipe(
  R.useWith(R.map, [
    R.flip(R.objOf),
    R.identity
  ]),
  R.mergeAll
)
Mick Dekkers
@mickdekkers
Apr 25 2017 11:06
@tusharmath Nice, thanks! useWith looks useful :D
Tushar Mathur
@tusharmath
Apr 25 2017 11:08
Glad to be of help :)
Functional SC
@functional_sc_twitter
Apr 25 2017 13:46
Hey, total N00B question: how do I stuff Ramda syntax support into Atom? (like min when typing in "mi"...) ...or should I be bothering the Atom guys?
James Forbes
@JAForbes
Apr 25 2017 13:47
@functional_sc_twitter um not sure about atom, in vscode, it will automatically download type definitions for npm dependencies
I think in atom you need to manually tell your editor where tsds are, and manually obtain them in atom, but I think its pretty easy
something like typings install ramda
not sure, I'm not an atom person
Functional SC
@functional_sc_twitter
Apr 25 2017 14:00
thanks
James Forbes
@JAForbes
Apr 25 2017 14:00
:+1:
Adrian Cooney
@adriancooney
Apr 25 2017 17:23
Hi folks, just wondering does Ramda have a sort of composeWhile or pipeWhile? I'm trying to pipe a value through various functions while it's not null. Any ideas? Thanks!
(I also need the output of the last function to be the return value, sorta like map the value through a list of functions while it's not null)
Matthew Willhite
@miwillhite
Apr 25 2017 17:35
@adriancooney you may want to look at Maybe or Either…
James Forbes
@JAForbes
Apr 25 2017 17:37
@adriancooney reduceWhile should do the trick
Matthew Willhite
@miwillhite
Apr 25 2017 17:39
:100:
James Forbes
@JAForbes
Apr 25 2017 17:40
:sparkles:
Jethro Larson
@jethrolarson
Apr 25 2017 19:03
I commonly want to update a record with some id in a list. Is there a nice way to do that using lenses?
Kurt Milam
@kurtmilam
Apr 25 2017 19:04
@jethrolarson yes. Give me a sec, and I'll work something up for you if nobody beats me to it.
Jethro Larson
@jethrolarson
Apr 25 2017 19:06
Thanks
I'd started working it out here https://goo.gl/wHzh43
but it's awkward and I'm hoping to extract a pattern that will work in more scenarios
Kurt Milam
@kurtmilam
Apr 25 2017 19:33
@jethrolarson actually, are you interested in a lenses library with a good deal more functionality?
What you're trying to do with Ramda lenses would be easier with partial.lenses.
I'll work up an example with partial.lenses. In the meantime, here's a readable and writable lens that's more complex than what you need, using partial.lenses.
Rick Medina
@rickmed
Apr 25 2017 19:39
@kurtmilam do you know the build size of partial. Lenses?
Kurt Milam
@kurtmilam
Apr 25 2017 19:47
@rickmed I'll check it and let you know.
@jethrolarson this works with partial.lenses:
const teasers =
  [ { uuid: 1
    , v: 1
    }
  , { uuid: 2
    , v: 2
    }
  ]

const newTeaser = { uuid:4, v:4 }

const withIdL = uuid => L.find( R.propEq( 'uuid', uuid ) )

const getByUuid = uuid => L.get( withIdL( uuid ) )
const setByUuid = uuid => L.set( withIdL( 2 ) )
getByUuid( 2 )( teasers )
setByUuid( 2 )( newTeaser, teasers )
Note: the lens is defined on a single line - no separate getter and setter necessary. The lens and get/set functions are reusable with any list of objects that have a 'uuid' property.
Kurt Milam
@kurtmilam
Apr 25 2017 19:55
@rickmed 11.6KB, minified, if I'm not missing something. See here.
Kurt Milam
@kurtmilam
Apr 25 2017 20:00
Made a mistake above - this is the correct definition for setByUuid:
const setByUuid = uuid => L.set( withIdL( uuid ) )
Kurt Milam
@kurtmilam
Apr 25 2017 20:07
@jethrolarson Don't want to spam up the joint, but I shortened things a little with R.compose:
const teasers = [ { uuid: 1, v: 1 }, { uuid: 2, v: 2 } ]
const newTeaser = { uuid: 4, v: 4 }
const withUuidL = R.compose( L.find, R.propEq( 'uuid' ) )
const getByUuid = R.compose( L.get, withUuidL )
const setByUuid = R.compose( L.set, withUuidL )
getByUuid( 2 )( teasers )
setByUuid( 2 )( newTeaser, teasers )
Jethro Larson
@jethrolarson
Apr 25 2017 20:29
Thanks a bunch. I suspected that I'd want to use another library
Galileo Sanchez
@galileopy
Apr 25 2017 21:04
any suggestions on how to improve this??
R.apply(R.useWith(R.merge, [R.objOf('A'), R.objOf('B')]))([1,2])
zipObj(['A', 'B'], [1,2])
Galileo Sanchez
@galileopy
Apr 25 2017 21:10
I think there should be a reference in props to zipObj, since they are related in a sense, I don't know if it is appropriate to call one the inverse of the other, but it's in the neighborhood
Rick Medina
@rickmed
Apr 25 2017 21:23
@kurtmilam thanks!
Denis Stoyanov
@xgrommx
Apr 25 2017 22:44
@galileopy ?
Galileo Sanchez
@galileopy
Apr 25 2017 23:16
@ram-bot
and(equals(props(['a', 'b'],  {a: 1, b: 2}), [1, 2])
    ,equals(zipObj(['a', 'b'], [1, 2]), {a: 1, b: 2})) === true
ram-bot
@ram-bot
Apr 25 2017 23:16
true