These are chat archives for ramda/ramda

25th
Apr 2016
James Forbes
@JAForbes
Apr 25 2016 03:48

Is there a notion in FP for explaining the relationship between two different units in a strongly typed manner.

e.g. an hour and a minute are trivially converted. But is there a way to represent that conversion in the type system, and then to lift the conversion easily within composition.

Say you want to call the typical add function on 1h and 30min and then receive either 90min or 1.5hwithout informing add about the conversion required.

Is there a nice approach in FP for representing the unit's requirements in a strongly typed manner, and then to freely and automatically convert two units into a compatible dimension so they can interact.

Or is there even a standard method / API for handling converting between units. I assume there is because of FP's strong mathematical leanings.

James Forbes
@JAForbes
Apr 25 2016 04:16

There seems to be some pretty powerful units of measure related type stuff in F#

https://books.google.com.au/books?id=gzVdyw2WoXMC&lpg=PA163&ots=IXZdMqZYMI&dq=a%20functional%20programming%20type%20for%20representing%20units%20of%20measurement&pg=PA163#v=onepage&q=a%20functional%20programming%20type%20for%20representing%20units%20of%20measurement&f=false

Essentially letting you define conversions between parameterized floats and define functions that only accept a particular unit.

Tycho Grouwstra
@tycho01
Apr 25 2016 06:19
Hi. I was looking into adopting ramda and ramda-fantasy, and I was wondering, are there any TypeScript definitions available for ramda-fantasy?
Baqer Mamouri
@bmamouri
Apr 25 2016 11:06

Hey peeps,

How can you get a prop in an array of object. Something like 0.email assuming we want the property email of the first item in the array

Baqer Mamouri
@bmamouri
Apr 25 2016 11:24
I found the answer. I needed R.pathOr
彭凡
@IvanPeng2015
Apr 25 2016 12:14
hello, how to simplify the function "vdiz"? without parameter "fn".
const aprop = R.converge(R.reduce(R.add,0),[R.map]);
const vdiz = fn => R.pipe(R.concat([]),aprop(fn));
Scott Christopher
@scott-christopher
Apr 25 2016 12:46
@IvanPeng2015 Are you wanting vdiz to take a function and a list, which first maps the function over the list and then calculates the sum of the mapped list?
Scott Christopher
@scott-christopher
Apr 25 2016 12:51
@ram-bot
const vdiz = pipe(map, reduce(add, 0))
vdiz(inc, [1, 2, 3])
ram-bot
@ram-bot
Apr 25 2016 12:51
9
Scott Christopher
@scott-christopher
Apr 25 2016 12:55
@JAForbes I was looking into something similar in Scala a year or so ago and came across this http://www.squants.com which looks pretty nifty.
Never ended up using it, but it did offer some nice type-safe features.
Also this might be of interest :point_up: April 21, 2016 10:24 PM
彭凡
@IvanPeng2015
Apr 25 2016 13:01
This message was deleted
This message was deleted
vdi as the "fn" parameter of vdiz function
彭凡
@IvanPeng2015
Apr 25 2016 13:09
const vdi = R.curry((d, y) => {
  if (y) {
    return d ? y.key : y.name;
  }
  else {
    return 0;
  }
});
const aprop = R.converge(R.reduce(R.add,0),[R.map]);
const vdiz = fn => R.pipe(R.concat([]),aprop(fn));
let total = aprop(vdiz(vdi(true)))(vdiData);
example data ```
[[{key: 4, name: 10}, {key: 5, name: 11}, {key: 6, name: 12}],
    [{key: 4, name: 10}, {key: 5, name: 11}, {key: 6, name: 12}],
    [{key: 4, name: 10}, {key: 5, name: 11}, {key: 6, name: 12}],
[{name: 1}]];
James Forbes
@JAForbes
Apr 25 2016 15:57
@scott-christopher thanks, that iso trick looks great
@scott-christopher squants looks cool too