These are chat archives for ramda/ramda

13th
Sep 2018
Alex Deas
@alex-deas_gitlab
Sep 13 2018 11:48

Hey, does anyone know if there’s a function similar to cond that allows you to apply a preprocessor onto the transformer function:

So that something written like

  const formatValue = R.cond([
    [R.where({ value: R.is(DateTime), type: "datetime-local" }), R.pipe(R.prop("value"), (d: DateTime) => d.toFormat("HH:mm 'on' dd/MM/yyyy"))],
    [R.where({ value: R.is(DateTime), type: "date"}), R.pipe(R.prop("value"), (d: DateTime) => d.toFormat("dd/MM/yyyy"))],
    [R.T, R.always(props.value)]
])

could be written as

  const formatValue = R.cond([
    [R.where({ value: R.is(DateTime), type: "datetime-local" }), d => d.toFormat("HH:mm 'on' dd/MM/yyyy")],
    [R.where({ value: R.is(DateTime), type: "date" }), d => d.toFormat("dd/MM/yyyy")],
    [R.T, R.identity]
  ])
Alex Deas
@alex-deas_gitlab
Sep 13 2018 12:02
Actually it can be implemented with a one liner
const condProc = (proc, pairs) => R.cond(pairs.map(([p, t]) => [p, R.pipe(proc, t)]))