These are chat archives for ramda/ramda

22nd
Apr 2017
Rick Medina
@rickmed
Apr 22 2017 00:02
:)
Denis Stoyanov
@xgrommx
Apr 22 2017 00:05
@rickmed ramda's reduceBy
reduceBy' valueAlgebra keyFn = fmap (cata valueAlgebra) . unXMap . refix . fmap(keyFn &&& id)

countBy' :: (Base (f (c, a1)) ~ ListF (k, v), Recursive (f (c, a1)), Ord k, Num a, Functor f) => (a1 -> c) -> f a1 -> M.Map k a
countBy' = reduceBy' $ \case
  Nil -> 0
  Cons _ b -> b + 1

groupBy' :: (Base (f (c, a)) ~ ListF (k, a1), Recursive (f (c, a)), Ord k, Functor f) => (a -> c) -> f a -> M.Map k [a1]
groupBy' = reduceBy' (embed :: ListF a [a] -> [a])

indexBy' :: (Base (f (c, a)) ~ ListF (k, M.Map k1 a1), Recursive (f (c, a)), Ord k, Functor f) => (a -> c) -> f a -> M.Map k (M.Map k1 a1)
indexBy' = reduceBy' $ \case
  Nil -> M.empty
  Cons a _ -> a
@rickmed
dropWhile' :: (t -> Bool) -> [t] -> [t]
dropWhile' p = zygo (\case Nil -> []; Cons x xs -> x: xs) $ \case
  Nil -> []
  Cons x (a, b) -> if p x then b else x : a

filter' :: (t -> Bool) -> [t] -> [t]
filter' p = cata $ \case
  Nil -> []
  Cons a b -> if p a then a:b else b

-- takeWhile' :: (t -> Bool) -> [t] -> [t]
takeWhile' :: (Base t ~ ListF t1, Recursive t) => (t1 -> Bool) -> t -> [t1]
takeWhile' p = para $ \case
  Nil -> []
  Cons x (_, b) -> if p x then x : b else []
Rick Medina
@rickmed
Apr 22 2017 00:37
Zygo :)
Tushar Mathur
@tusharmath
Apr 22 2017 12:21
is there a simpler way to achieve this —
const TEMP = (f, g) => R.unapply(t => R.apply(f, R.map(g, t)))
essentially it takes two functions f and g and returns a new function which when called an any number of arguments, each arg is first passed to g and the result is then collected and passed to f
Michael Rosata
@mrosata
Apr 22 2017 13:07
@tusharmath isn't that just compose? or am I missing something?
Tushar Mathur
@tusharmath
Apr 22 2017 13:08
@mrosata I think its more like useWith with all the functions being the same in the array
Michael Rosata
@mrosata
Apr 22 2017 13:09
so your passing the derived function an array or just arbitrary number of args?
Tushar Mathur
@tusharmath
Apr 22 2017 13:10
second option — arbitary number of args
for eg:
const d = TEMP(
  (a, b, c) =>  [a, b, c],
  R.multiply(100)
)

// usage
d(1, 2, 3) // [100, 200, 300]
Denis Stoyanov
@xgrommx
Apr 22 2017 13:12
Traverse
Tushar Mathur
@tusharmath
Apr 22 2017 13:13
@xgrommx Example?
Denis Stoyanov
@xgrommx
Apr 22 2017 13:15
@ram-bot compose(map(x => x * 100), unapply(identity))(1,2,3)
ram-bot
@ram-bot
Apr 22 2017 13:15
[ 100, 200, 300 ]
Denis Stoyanov
@xgrommx
Apr 22 2017 13:16
why not?
Tushar Mathur
@tusharmath
Apr 22 2017 13:20
That just solves the above problem @xgrommx
What I really want is —
TEMP(
  R.equals,
  R.nth(2)
)
So two arrays are equal if the elements on 2 are equal
Michael Rosata
@mrosata
Apr 22 2017 13:22
I never really think that multiple arguments can be passed to compose (which obviously it can as in @xgrommx answer above). Makes sense in JS anyways
so unapply(identity) === (...xs) => xs basically. That's good to know
Denis Stoyanov
@xgrommx
Apr 22 2017 13:29
First function of composition will be to has many args
Michael Rosata
@mrosata
Apr 22 2017 13:29
yea, it will just apply over all the arguments
I don't know why I don't think of it that way. In a language like Haskell it wouldn't work that way though correct? Where everything is curried. You'd have to pass a tuple or something because the 2nd argument would be applied over by the result of the composition being applied over the first argument, *I believe
Denis Stoyanov
@xgrommx
Apr 22 2017 13:43
In haskell arity of function equal 1 for correct currying
This is from lambda calculus
Also in haskell u can use tuple, triple and etc
Michael Rosata
@mrosata
Apr 22 2017 13:44
javascript is variadic so technically there is no difference in the way composition works. It's just the arity constraints
Denis Stoyanov
@xgrommx
Apr 22 2017 13:45
JavaScript is uglyadic language :smile:
Michael Rosata
@mrosata
Apr 22 2017 13:45
lol
Denis Stoyanov
@xgrommx
Apr 22 2017 13:46
Anyway I'm frontend developer :smile:
Tushar Mathur
@tusharmath
Apr 22 2017 13:46
@xgrommx What do u use haskel for?
Michael Rosata
@mrosata
Apr 22 2017 13:46
Me too. Full stack I guess is more accurate. I feel like I'm mostly working in the front-end though.
I only use Haskell for fun really and learning
Denis Stoyanov
@xgrommx
Apr 22 2017 13:46
Now just for fun only learn it
Ahaha
Michael Rosata
@mrosata
Apr 22 2017 13:47
lol. nice
Denis Stoyanov
@xgrommx
Apr 22 2017 13:47
But I really like it
Recursion schemes and etc
Michael Rosata
@mrosata
Apr 22 2017 13:48
Me too, I started out reading Birds introduction to functional programming with Haskell and then eventually fell back to "Learn You Haskell"
Denis Stoyanov
@xgrommx
Apr 22 2017 13:48
In past I was backend developer (php, .Net)
I have a big list of FP :smile:
Rick Medina
@rickmed
Apr 22 2017 13:49
@xgrommx at least you upgraded from php, no?
Michael Rosata
@mrosata
Apr 22 2017 13:49
I started with PHP, never used .net. I did have to scrape data from a .net site once with PHP. It was a huge pain because of the way .net implements "state". And then a few months later it broke (the php)
@rickmed I'm glad to be done with PHP :)
Denis Stoyanov
@xgrommx
Apr 22 2017 13:50
I have some experience with Java, .Net, php, scala,f#, python))) i like to try a new languages
But now haskell :heart:
Yes this is hard to learn language but anyway I need do it :smile:
Michael Rosata
@mrosata
Apr 22 2017 13:52
I spent a lot of time with Python. I've never written scala, but I can read it a bit. I read through some Scala articles, I really liked syntax. Haskell is my love at the moment as well
Although the past 2 weeks I've been too busy to use it
Rick Medina
@rickmed
Apr 22 2017 13:52
honestly, js "the good parts" is not that terrible -specially, with an awesome community
Denis Stoyanov
@xgrommx
Apr 22 2017 13:53
Future of js is terrible
Michael Rosata
@mrosata
Apr 22 2017 13:53
JS is awesome. I love JavaScript. And your right @rickmed it's the community that is awesome
Rick Medina
@rickmed
Apr 22 2017 13:53
@mrosata you really liked scala's syntax? :flushed:
Michael Rosata
@mrosata
Apr 22 2017 13:53
yea I do
Denis Stoyanov
@xgrommx
Apr 22 2017 13:53
I bet on llvm and webassembly
Michael Rosata
@mrosata
Apr 22 2017 13:53
But it could just be that I haven't used it. It's always fun puzzling out new things
Rick Medina
@rickmed
Apr 22 2017 13:54
@mrosata I admire you my friend :)
Michael Rosata
@mrosata
Apr 22 2017 13:54
@xgrommx I feel like we've been waiting on webassembly for a long time now. I do hope it is the future though, it makes sense anyways
@rickmed lol
Denis Stoyanov
@xgrommx
Apr 22 2017 13:54
I don't like scala syntax also as a Java because it is really noisly
Rick Medina
@rickmed
Apr 22 2017 13:54
webassembly won't replace js anytime soon if ever
Denis Stoyanov
@xgrommx
Apr 22 2017 13:55
In JVM i like Kotlin)
Rick Medina
@rickmed
Apr 22 2017 13:55
there is a nice quora post from the folktale's author about it
Michael Rosata
@mrosata
Apr 22 2017 13:55
@rickmed yea, the world runs on JavaScript right now
Denis Stoyanov
@xgrommx
Apr 22 2017 13:56
Haskell -> llvm -> webassembly
Rick Medina
@rickmed
Apr 22 2017 13:56
at the end, is not about js (ecma), is about the browser vendors. The web has too much distribution power, and js is at its heart
Michael Rosata
@mrosata
Apr 22 2017 13:57
yea, I heard mozilla won't implement a change in the browser if it breaks something like 0.000001% of the sites in the world (don't qoute me on that)
It's not even about replacing JavaScript ever anyways, it's about getting things to work together well imo
Rick Medina
@rickmed
Apr 22 2017 14:00
yeah, is a consequence of having a common environment that too many people consume and produce for it and for too much time (legacy)
Michael Rosata
@mrosata
Apr 22 2017 14:00
@xgrommx there is a haskell -> js kit somewhere out there. Is there a Haskell llvm?
Rick Medina
@rickmed
Apr 22 2017 14:00
there is ghcjs
but the runtime is heavy
Denis Stoyanov
@xgrommx
Apr 22 2017 14:01
I know about haskell to llvm and llvm to js, but I don't know about haskell llvm js
Rick Medina
@rickmed
Apr 22 2017 14:01
I think I saw some tweet about someone implementing llvm
Denis Stoyanov
@xgrommx
Apr 22 2017 14:01
Yes, ghcjs
Fay
Haste
Michael Rosata
@mrosata
Apr 22 2017 14:01
@rickmed agreed. JavaScript being a superset is one of the best and worst features of the language. It's awesome to support legacy, it makes big evolution difficult though
Denis Stoyanov
@xgrommx
Apr 22 2017 14:01
Also purescript elm
Idris :smile:
More powerful typescript than js
Michael Rosata
@mrosata
Apr 22 2017 14:02
I've heard a lot about Elm
Rick Medina
@rickmed
Apr 22 2017 14:02
lately I've been studying prolog :) :heart:
Michael Rosata
@mrosata
Apr 22 2017 14:02
I think Idris is the Haskell -> js that I was thinking about. I saw a presentation on it
Rick Medina
@rickmed
Apr 22 2017 14:03
@xgrommx what is the difference between idris and agda?
Michael Rosata
@mrosata
Apr 22 2017 14:03
I don't know prolog
Denis Stoyanov
@xgrommx
Apr 22 2017 14:03
Elm has runtime, ghcjs has runtime by purescript not
@rickmed hard question for me
Rick Medina
@rickmed
Apr 22 2017 14:04
I've found logic programming very useful for mindset growth, just as OOP -> FP
Denis Stoyanov
@xgrommx
Apr 22 2017 14:04
But purescript not (sorry typo)
I'm from phone now :smile:
Rick Medina
@rickmed
Apr 22 2017 14:04
:)
Michael Rosata
@mrosata
Apr 22 2017 14:06
@rickmed I only heard about logic programming after starting to learn FP, and my first instinct was to try to learn it. But I think it will be better for me to spend at least another year in FP with Haskell before looking into logic
Denis Stoyanov
@xgrommx
Apr 22 2017 14:07
I learned prolog and lisp in my highschool
I was starting to learn Fp from Rxjs
In end of 2014
It was my rxbook :smile:
Michael Rosata
@mrosata
Apr 22 2017 14:10
RxJS is very cool. Also very big
Rick Medina
@rickmed
Apr 22 2017 14:10
@mrosata :+1: . I got interested for a specific project i have in mind. Is a very simple language (probably not that easy to write code in it)
Michael Rosata
@mrosata
Apr 22 2017 14:10
or at least it was. It could be different
Denis Stoyanov
@xgrommx
Apr 22 2017 14:10
No very big rx4
Rick Medina
@rickmed
Apr 22 2017 14:10
I was starting to learn Fp from Rxjs
me as well!
Denis Stoyanov
@xgrommx
Apr 22 2017 14:10
:smile:
Rick Medina
@rickmed
Apr 22 2017 14:11
@xgrommx I think you answered some of my questions in the rxjs room a while back
Denis Stoyanov
@xgrommx
Apr 22 2017 14:11
I like join pattern in rx4, baconjs (but it is really easy to implement with merge,zip, scan)
@rickmed maybe)
Michael Rosata
@mrosata
Apr 22 2017 14:12
I like bacon
Denis Stoyanov
@xgrommx
Apr 22 2017 14:12
I like too much reactive libs))
Rick Medina
@rickmed
Apr 22 2017 14:13
I think reactive is a good gateway to fp
Michael Rosata
@mrosata
Apr 22 2017 14:13
well they are nice
I think FP was my gateway to RP actually
Denis Stoyanov
@xgrommx
Apr 22 2017 14:13
Frp yes, just reactive no
Tushar Mathur
@tusharmath
Apr 22 2017 14:13
@xgrommx I created one of my own — https://github.com/tusharmath/observable-air
idea was to make it fast as mostjs but also easily testable like rxjs.
Denis Stoyanov
@xgrommx
Apr 22 2017 14:13
Do u have to see sodium typescript?
Tushar Mathur
@tusharmath
Apr 22 2017 14:14
its only 4kb in production gzip and minified and all functions are curried
Michael Rosata
@mrosata
Apr 22 2017 14:14
Nice! @tusharmath
Denis Stoyanov
@xgrommx
Apr 22 2017 14:14
I know about it :smile:
Michael Rosata
@mrosata
Apr 22 2017 14:14
I'm bookmarking it so I can look through it later
Tushar Mathur
@tusharmath
Apr 22 2017 14:15
@mrosata Thanks :)
Rick Medina
@rickmed
Apr 22 2017 14:15
I don't use rxjs at all anymore. Too bloated
Denis Stoyanov
@xgrommx
Apr 22 2017 14:15
Flyd :smile:
Rick Medina
@rickmed
Apr 22 2017 14:15
@tusharmath cool! I have thought of doing something similar!
Michael Rosata
@mrosata
Apr 22 2017 14:15
I started to make something similar but it's probably not 100
Rick Medina
@rickmed
Apr 22 2017 14:15
yeah, flyd is my current go to choice
Michael Rosata
@mrosata
Apr 22 2017 14:15
% sound
https://github.com/mrosata/micro-stream -- if I could rewrite it now knowing what I do, I think it would be better
I did add recently though this file https://github.com/mrosata/micro-stream/blob/master/src/lazy.class.js which basically implements lazy evaluation
Rick Medina
@rickmed
Apr 22 2017 14:17
@tusharmath is it hot/cold by default?
Denis Stoyanov
@xgrommx
Apr 22 2017 14:17
or warm :smile:
Michael Rosata
@mrosata
Apr 22 2017 14:18
cold
Tushar Mathur
@tusharmath
Apr 22 2017 14:18
@rickmed Cold
Michael Rosata
@mrosata
Apr 22 2017 14:18
I think it's cold (meaning that if no subscribers then no action)
Tushar Mathur
@tusharmath
Apr 22 2017 14:18
@mrosata Right
The scheduler is the main feature IMHO.
Denis Stoyanov
@xgrommx
Apr 22 2017 14:19
warm will be with Observable.defer :smile:
@tusharmath a most architecture?
Tushar Mathur
@tusharmath
Apr 22 2017 14:20
Not exactly
But the same optimizations
Denis Stoyanov
@xgrommx
Apr 22 2017 14:20
This message was deleted
Tushar Mathur
@tusharmath
Apr 22 2017 14:21
Yeah more like Rxjs
Rick Medina
@rickmed
Apr 22 2017 14:21

warm will be with Observable.defer

I think it's around 25 °C

Denis Stoyanov
@xgrommx
Apr 22 2017 14:21
:smile:
Michael Rosata
@mrosata
Apr 22 2017 14:21
@tusharmath the documentation link is broken
Observable-Air is a catchy name
Tushar Mathur
@tusharmath
Apr 22 2017 14:21
Sorry about that
Im working on the documentation
Take a look the functions exposed here
I wanted a super light weight library so called it Air :)
Denis Stoyanov
@xgrommx
Apr 22 2017 14:23
Tushar Mathur
@tusharmath
Apr 22 2017 14:23
@xgrommx Agree, mostly its done for v8 optimizations.
and win in the micro benchmarks
Michael Rosata
@mrosata
Apr 22 2017 14:24
I was going to say, I agree on the style. Speed could be an issue
Denis Stoyanov
@xgrommx
Apr 22 2017 14:25
@tusharmath yes, this is problem, because optimization possible only for OOP way
Michael Rosata
@mrosata
Apr 22 2017 14:26
I think that speed in JavaScript though might have less to do with the way you write code and more to do with the way the rest of the world writes code... if that makes any sense
Tushar Mathur
@tusharmath
Apr 22 2017 14:26
Yes
But the thing is if the operators optimized then u can compose them easily to create more complicated operators without any overhead
For instance a lot of rxjs operators can be re-implemented using only some core operators but unfortunately they are not as fast
and the ones implemented using classes
Michael Rosata
@mrosata
Apr 22 2017 14:30
I think I got lost there, it sounds like the second part of that is saying the opposite of the first part. Unless I'm reading it wrong
Denis Stoyanov
@xgrommx
Apr 22 2017 14:30
sometime speed like in most, or more faster don't needed because, because....
Rick Medina
@rickmed
Apr 22 2017 14:30
a few simple and composable api FTW
Denis Stoyanov
@xgrommx
Apr 22 2017 14:31
React isn't fast, but
Vue more faster :smile:
Angular 2 will be more faster (render via Workers)
Michael Rosata
@mrosata
Apr 22 2017 14:32
That's cool stuff
So like server side rendering? But with workers?
Rick Medina
@rickmed
Apr 22 2017 14:32
imo, microbenchmarks are useless, only optimizations with algorithmic benchmarks if the gain is at least an order of magnitude
Tushar Mathur
@tusharmath
Apr 22 2017 14:32
@mrosata The composition in Air has very minimal overhead, unlike rxjs that's what I meant.
Denis Stoyanov
@xgrommx
Apr 22 2017 14:33
yes, we need to go deeper in Algorithms and Data Structures (Tree, RoseTree, List, etc) :smile:
Michael Rosata
@mrosata
Apr 22 2017 14:33
@tusharmath ok, that's how I started reading it, but for some reason the last part I thought you were saying they were not
Tushar Mathur
@tusharmath
Apr 22 2017 14:34
Sorry, hope that clear now?
Michael Rosata
@mrosata
Apr 22 2017 14:34
it is thanks
Tushar Mathur
@tusharmath
Apr 22 2017 14:34
too many thoughts slow typing speed :(
Michael Rosata
@mrosata
Apr 22 2017 14:34
yea, lol
:shipit:
Denis Stoyanov
@xgrommx
Apr 22 2017 14:35
what is DOM? DOM is a RoseTree. We can make RoseTree - Functor, Monoid, Applicative, Traversable, Foldable and etc even Monad!
Tushar Mathur
@tusharmath
Apr 22 2017 14:36
@rickmed sorry but I don't completely agree with you here. Microbenchmarks are really important sometimes.
Rick Medina
@rickmed
Apr 22 2017 14:36
@tusharmath have you seen this talk? https://www.youtube.com/watch?v=65-RbBwZQdU
Michael Rosata
@mrosata
Apr 22 2017 14:38
Microbenchmarks aren't useless. But they aren't the complete picture
Rick Medina
@rickmed
Apr 22 2017 14:38
microbenchmarks: while(++) vs while(--), things like that
Tushar Mathur
@tusharmath
Apr 22 2017 14:38
@rickmed I have :)
I think his point AFAIK was to really understand what makes some benchmarks faster than others
Denis Stoyanov
@xgrommx
Apr 22 2017 14:40
Useful only real cases.
Rick Medina
@rickmed
Apr 22 2017 14:41
I think his point is that the vm will eat your lunch if you try to outsmart it :)
Tushar Mathur
@tusharmath
Apr 22 2017 14:41
For me personally, while doing animations I realised that each ms that I can save is of utmost importance.
Rick Medina
@rickmed
Apr 22 2017 14:42
unless, for VERY known poor optimizations like recursion in js
anyway, fp and langs are much more fun topics :)
Rick Medina
@rickmed
Apr 22 2017 14:49
what do you guys think about csp?
Tushar Mathur
@tusharmath
Apr 22 2017 14:49
not a big fan
:)
Rick Medina
@rickmed
Apr 22 2017 14:49
my thoughts exactly
Denis Stoyanov
@xgrommx
Apr 22 2017 14:49
Continuation sequence processes?
Rick Medina
@rickmed
Apr 22 2017 14:50
communicating*
as in go lang
Denis Stoyanov
@xgrommx
Apr 22 2017 14:51
Oh) sorry
Tushar Mathur
@tusharmath
Apr 22 2017 15:08
Javascript is not the best language to start programming with :P
The quirks start feeling natural
Rick Medina
@rickmed
Apr 22 2017 15:13
is it in this room someone posted the dijkstra's letter to a university about haskell?
Kurt Milam
@kurtmilam
Apr 22 2017 16:13
Take a look at calmm-js for frp with lenses, as well. I'm finding it very nice, indeed.
calmm-js is react + partial.lenses + kefir (or bacon) + atoms.
Kurt Milam
@kurtmilam
Apr 22 2017 17:30
Forgot to mention, calmm-js also makes heavy use of Ramda, so Ramda-lovers should feel right at home.
(PDF)
Brad Compton (he/him)
@Bradcomp
Apr 22 2017 17:59
not found :(
Kurt Milam
@kurtmilam
Apr 22 2017 18:00
Encoding problem. Unfortunately I'm in a phone, and the url didn't survive the copy and paste 😞
Second try: PDF is available here
Brad Compton (he/him)
@Bradcomp
Apr 22 2017 18:01
%2520 -> %20 got it :)
Kurt Milam
@kurtmilam
Apr 22 2017 18:02
😡
Thanks!
Denis Stoyanov
@xgrommx
Apr 22 2017 20:53
Brad Compton (he/him)
@Bradcomp
Apr 22 2017 21:57
Looks like it's using inline property based testing to check invariants.
Cody
@Condell
Apr 22 2017 23:29
I'm so thankful this room is here lol. I have a question about using, well, I guess Functional Programming in general in Node along with Express. Does anyone have any advice on how to make "app.get()" and other routes pure? Or is there a best practice here? I've been thinking and looking, but all I could come up with is either wrap each route in an IO or Future, or just write the rest of the program using Ramda, then call the composed function inside of the get or post or whatever callback function, leaving app.get impure. Or is there another library I'm missing? Or should I look into RxJS?