Scala.js With Monix Example

Tags: , , , ,

Scala.js With Monix Example

Scala.js With Monix Example

One of the annoying thing in front-end development is managing long calculations in a browser. JavaScript does things synchronously, and when you want to do something, that needs time for execution, JavaScript resists. Here is an example of such long calculation. At first, I shall demonstrate synchronous code, then asynchronous. Scala has the great library Monix, that works well with Scala.js. I have already told about Monix in some of my previous posts. Of cause, I’m going to use this library in my asynchronous example. My son goes to school. One time he was doing his math homework and he

Continue Reading

Learn You Scala for Great Good! Part 6

Learn You Scala for Great Good! Part 6

Today I want to finish this long talk about Haskell and Scala.  The only thing that  stays in my to-do list is  “A knight’s quest”. Please look at my previous posts: Learn You Scala for Great Good! Learn You Scala for Great Good! Part 2 Learn You Scala for Great Good! Part 3 Learn You Scala for Great Good! Part 4 Learn You Scala for Great Good! Part 5   A knight’s quest Here’s a problem that really lends itself to being solved with non-determinism. Say you have a chess board and only one knight piece on it. We want

Continue Reading

Learn You Scala for Great Good! Part 5

Scala and Haskell are both good for functional programming. And in some cases their approaches for problems solving are very similar. This is my fifth post of this theme. The idea of writing this series appeared when I was looking for a book about functional programming in Scala. It happened that I found Learn You Haskell for Great Good – the great book about Haskell. I started reading it. Today I want to take some examples from the Higher order functions Chapter of this book Please look at my previous posts: Learn You Scala for Great Good! Learn You Scala

Continue Reading

Learn You Scala for Great Good! Part 4

It’s my fourth post of the series where I told how I started studying Haskell in order to get knowledge in functional programming in Scala. You may see previous posts on this theme: Learn You Scala for Great Good! Learn You Scala for Great Good! Part 2 Learn You Scala for Great Good! Part 3 Today I want to take the three last examples from the Recursion Chapter.   zip function It takes two lists and zips them together. zip [1,2,3] [2,3] returns [(1,2),(2,3)], because it truncates the longer list to match the length of the shorter one. Haskell zip

Continue Reading

Learn You Scala for Great Good! Part 3

In my previous posts Learn You Scala for Great Good! and Learn You Scala for Great Good! Part 2 I told how I started studying Haskell in order to get knowledge in functional programming in Scala. While I was reading Learn You a Haskell for Great Good! I started to “translate” some examples from Haskell into Scala. Today I shall take some interesting examples from the Recursion chapter of this book. replicate function The replicate function takes an Int and some element and returns a list that has several repetitions of the same element.   Haskell replicate :: (Num i,

Continue Reading

Learn You Scala for Great Good! Part 2

Last time I wrote about my experience in learning of functional programming basics using Learn You a Haskell for Great Good! with accent on Scala. Today I’m going to use an example from the Recursion chapter. Maximum awesome In Haskell example the maximum function takes a list of things that can be ordered (e.g. instances of the Ord typeclass) and returns the biggest of them. maximum :: (Ord a) => [a] -> a maximum [] = error “maximum of empty list” maximum [x] = x maximum (x:xs) | x > maxTail = x | otherwise = maxTail where maxTail =

Continue Reading

Learn You Scala for Great Good!

I came to Scala from Java. So when I wanted to learn Scalaz, I didn’t know what to start with. I decided that the best way would be to start with functional programming. It’s strange but the best manual was Learn You a Haskell for Great Good! Yes, I chose my way: I started learning Haskell in order to know Scala better! For better understanding I started to “translate” Haskell examples into Scala. Now I have decided to publish these examples. Guards, guards! We’re going to make a simple function that berates you differently depending on your BMI (body mass

Continue Reading