These are chat archives for ramda/ramda

14th
May 2017
Jesse Atkinson
@jsatk
May 14 2017 00:21
Thank you @kedashoe !
diqye
@diqye2014
May 14 2017 06:06
O(∩_∩)O~
Michael Rosata
@mrosata
May 14 2017 13:58
What would be the equivalent of the T-Combinator (thrush) in Ramda?
const thrush = (x) => (f) => f(x)
const sentence = R.curry((a, b, c) => `${ a } ${ b } ${ c }`)
const aToZ = compose(thrush('Zed'), thrush('to'), thrush('A'))
aToZ(sentence)  // "A to Zed"
Denis Stoyanov
@xgrommx
May 14 2017 14:03
@mrosata flip + apply
@mrosata or maybe flip(identity)
Michael Rosata
@mrosata
May 14 2017 14:05
Alright, so then thrush could be made by C(I) or C(A) where C = flip and A = Apply.
I'll have to test it. R.apply and const A = (f) => (x) => f(x) have different behaviour of coarse.
Denis Stoyanov
@xgrommx
May 14 2017 14:06
@mrosata
C(I) x y
I(y)(x) = y x
proof via SK
S(K(S((S(K))(K))))(K)xy;
S = a -> b -> c -> (a c)(b c)

(K(S((S(K))(K))) x)(K x) y

S((S(K))(K)) (K x) y

((S(K))(K) y) (K x y)

SKKy === Iy = y

(y) (x)
where C = S(S(K(B))(S))(K(K))
Michael Rosata
@mrosata
May 14 2017 14:10
cool, thanks
Is Thrush somewhat isomorphic to Monad.chain as well?
Denis Stoyanov
@xgrommx
May 14 2017 14:11
@mrosata hmmm, no
Michael Rosata
@mrosata
May 14 2017 14:12
what would be the equiv of thrush with a monad? Just map(Thrush)?
Denis Stoyanov
@xgrommx
May 14 2017 14:12
@mrosata
// K :: a -> b -> a
const K = x => y => x;
// S :: (a -> b -> c) -> (a -> b) -> a -> c
const S = x => y => z => x(z)(y(z));
// I :: a -> a
const I = S(K)(K);
// I_ :: (a -> b) -> a -> b
const I_ = S(S(K));
// B :: (b -> c) -> (a -> b) -> a -> c
const B = S(K(S))(K);
// B1 ::
const B1 = B(B)(B);
// C :: (a -> b -> c) -> b -> a -> c
const C = S(B(B)(S))(K(K));
// W :: (a -> a -> b) -> a -> b
const W = S(S)(S(K));
// W__ :: (a -> b -> c -> c -> d) -> a -> b -> c -> d
const W__ = B(B(W));
// Q :: (a -> b) -> (b -> c) -> a -> c
const Q = C(B);

const MO = B1(W)(B);
const MO1 = B(B(W))(B);

// console.log(MO1(x => y => x * y)(x => x * 10)(10));

module.exports = { S, K, I, B, C, W, W__, Q };
MO,MO1 is chain for function
Michael Rosata
@mrosata
May 14 2017 14:13
Alright, thanks. I need to look at this closer later. I have to go out for Mothers Day. I will be back in a few hours though.
Vlad Sabev
@vdsabev
May 14 2017 21:08

Hey, everyone :) I'm just getting into FP, implementing my own functions for fun and learning, and hit a wall with composing a function. I'm thinking it's either really simple or completely impossible, and I would really appreciate your help with this:

// What I'm trying to simplify
const is = (typeToCompare: string) => (value: any) => equal(typeToCompare)(type(value));
// Or using compose
const is = (typeToCompare: string) => compose(equal(typeToCompare), type);
// Example usage
const isNumber = is('number');
isNumber(1); // true

// A more mathematical representation
const a = (x) => (y) => f(x)(g(y));
// Or using compose
const b = (x) => compose(f(x), g);

This works fine, my goal is to do it without using a closure / anonymous function. Any ideas?

Riderman de Sousa Barbosa
@Ridermansb
May 14 2017 21:20
Thanks @Yord
Michael Rosata
@mrosata
May 14 2017 21:25
@vdsabev I could likely help you tomorrow if you haven't found assistance, that's probably too late. In the meantime, the combinators that @xgrommx posted could be helpful to abstract some of the functions you are trying to make point free. I found for me, combinators 'S', 'C', 'D', 'J' and 'C' are useful. C-combinator is R.flip, http://ramdajs.com/docs/#flip, there are functions like http://ramdajs.com/docs/#converge converge (which is a bit like an S-combinator), converge is good for refactoring some patterns that won't fit into composition because input must be applied over by multiple functions then used together to call another function. Just as ideas (JavaScript combinators can easily be referenced here https://www.npmjs.com/package/combinators-js)
Vlad Sabev
@vdsabev
May 14 2017 21:26
@mrosata thanks for the links, I'll take a look and try to find a pattern similar to my function
Michael Rosata
@mrosata
May 14 2017 21:27
@vdsabev np, gl
Michael Rosata
@mrosata
May 14 2017 22:02
@xgrommx nice, thanks. I never noticed the calculator at the bottom of that page. When your using combinators in your programs, I assume you would use the lambda versions rather than the SK(I) versions correct? Implementing other combinators with SK combos is just an academic pursuit basically? Just proof that all combinators can be created using S and K correct?
I do like the comparisons of the combinators to their algebra equivs
Actually makes them easier to digest, knowing their purpose