These are chat archives for ramda/ramda

14th
Jul 2017
freemember007
@freemember007
Jul 14 2017 14:59 UTC
你好
Denis Stoyanov
@xgrommx
Jul 14 2017 14:59 UTC
?
Kurt Milam
@kurtmilam
Jul 14 2017 15:08 UTC
ni hao :D
chi fan le ma?
Unfortunately, my Mandarin vocabulary doesn't go a whole lot further than that.
Ryan Bas
@ryanbas21
Jul 14 2017 16:04 UTC
is there a ramda method to make this type of logic more readable?
export const addCheckin = action => team =>
  team.teamID === action.payload.teamID
    ? { ...team, checkIns: R.concat(team.checkIns, [action.payload]) }
    : team;
I was looking at evolve but im not sure that would do it
Joe Egan
@joeegan
Jul 14 2017 16:19 UTC

Hi there, ramda newbie here, stuck on the following:

let subscription = 'foo';    
let client = { unsubscribe: F }

// standard
if (subscription) {
  client.unsubscribe(subscription);
  subscription = null;
}

// ramda'd!
ifElse(
  subscription,
  both(
    call('unsubscribe', subscription), 
    set(subscription, null)
  )
)(client, subscription) // Don't think you can pass two things here without another wrap

error: t.apply is not a function
https://goo.gl/o18xue

@ryanbas21 You could use equals for the === and ifElse for the ternary I think
Brad Compton (he/him)
@Bradcomp
Jul 14 2017 16:25 UTC
ifElse takes functions for its parameters, not values
Also, I am also not sure about passing multiple parameters either
R.ifElse
Brad Compton (he/him)
@Bradcomp
Jul 14 2017 16:26 UTC
Looks like it should work
Gimme a sec and I will get something working
Ryan Bas
@ryanbas21
Jul 14 2017 16:31 UTC
not sure if using equals and ifElse makes it any more readable tbh for me
Brad Compton (he/him)
@Bradcomp
Jul 14 2017 16:32 UTC
R.when
Philipp Wille
@Yord
Jul 14 2017 16:33 UTC
@ryanbas21 How about:
const addCheckin = action => when(
  eqProps('teamID', action.payload),
  evolve({
    checkIns: append(action.payload)
  })
)
Ryan Bas
@ryanbas21
Jul 14 2017 16:35 UTC
that looks really good actually @Yord , im gonna look at these methods, thanks
Brad Compton (he/him)
@Bradcomp
Jul 14 2017 16:36 UTC
this works, but I agree it isn't any clearer
Joe Egan
@joeegan
Jul 14 2017 16:38 UTC
@Bradcomp Thanks, that's really helpful
Ryan Bas
@ryanbas21
Jul 14 2017 16:38 UTC
@Yord so eqProps how does it compare 'teamID' to action.payload and the object that map is on? because i'm using it as R.map(addCheckin(action), state.teams and it passes my test, im just trying to follow it
Philipp Wille
@Yord
Jul 14 2017 16:45 UTC
@ryanbas21 I'll just explicitly write out all parameters. That should explain:
const addCheckin = action => team => when(
  team => eqProps('teamID', action.payload, team),
  team => evolve({
    checkIns: checkIns => append(action.payload)(checkIns)
  })(team)
)(team)

map(team => addCheckin(action)(team), state.teams)
λ • Geovani de Souza
@geovanisouza92
Jul 14 2017 17:26 UTC
Hello everyone! I'm curious about what are the most common functions that you use. Mine are:
17 const compose = require('ramda/src/compose')
14 const assoc = require('ramda/src/assoc')
13 const merge = require('ramda/src/merge')
11 const prop = require('ramda/src/prop')
 8 const defaultTo = require('ramda/src/defaultTo')
 8 const curry = require('ramda/src/curry')
 6 const props = require('ramda/src/props')
 5 const propOr = require('ramda/src/propOr')
 5 const propEq = require('ramda/src/propEq')
 5 const omit = require('ramda/src/omit')
 5 const keys = require('ramda/src/keys')
 5 const always = require('ramda/src/always')
 4 const when = require('ramda/src/when')
 4 const join = require('ramda/src/join')
 4 const add = require('ramda/src/add')
 3 const pick = require('ramda/src/pick')
 3 const path = require('ramda/src/path')
 3 const ifElse = require('ramda/src/ifElse')
 3 const head = require('ramda/src/head')
 3 const has = require('ramda/src/has')
 3 const find = require('ramda/src/find')
 2 const sortBy = require('ramda/src/sortBy')
 2 const concat = require('ramda/src/concat')
 2 const clone = require('ramda/src/clone')
 1 const xprod = require('ramda/src/xprod')
 1 const values = require('ramda/src/values')
 1 const toPairs = require('ramda/src/toPairs')
 1 const times = require('ramda/src/times')
 1 const slice = require('ramda/src/slice')
 1 const repeat = require('ramda/src/repeat')
 1 const range = require('ramda/src/range')
 1 const over = require('ramda/src/over')
 1 const or = require('ramda/src/or')
 1 const memoize = require('ramda/src/memoize')
 1 const map = require('ramda/src/map')
 1 const lensProp = require('ramda/src/lensProp')
 1 const length = require('ramda/src/length')
 1 const identity = require('ramda/src/identity')
 1 const groupBy = require('ramda/src/groupBy')
 1 const filter = require('ramda/src/filter')
 1 const evolve = require('ramda/src/evolve')
 1 const equals = require('ramda/src/equals')
 1 const applySpec = require('ramda/src/applySpec')
Indeed, I'm planning to reduce that to fewer, reducing my (webpack) bundle size even more
Michael Rosata
@mrosata
Jul 14 2017 17:28 UTC
I like console.log
@geovanisouza92 what did you use to figure that out that list? Just search one by one or a tool?
λ • Geovani de Souza
@geovanisouza92
Jul 14 2017 17:29 UTC
cat <all folders>/*.js | grep -E "require\('ramda/src/\w+'\)" | sort | uniq -c | sort -gr (to find how many times it's imported)
If you are importing everyting, I think that cat <all folders>/*.js | grep -E "R\.\w+" | sort | uniq -c | sort -gr finds everything
Michael Rosata
@mrosata
Jul 14 2017 17:39 UTC
@geovanisouza92 ah, nice. Can you write one that reads a file from stdin and searches each function one by one? The functions can be put in a file with
const fs = require('fs')
const R = require('ramda')
fs.writeFileSync('ramda-functions.txt', Reflect.ownKeys(R).join('\n'), 'utf8')