This is a cheat sheet based on a great talk "How to specify it! A guide to writing properties of pure functions" by John Hughes. This talk has a lot of information easy to forget so a cheat sheet may help you refreshing memories without watching the whole talk again.
Functional Programming
7 postsA Good Way How to Validate Types in TypeScript
TL;DR: I've created a typescript library fp-ts-type-check. You can use it to validate the structure of data you get from outside of your application.
Here's the situation: your typescript application needs to retrieve some object via some API. You make an API request and you get a successful response with some json. Probably it's the data you expect but you can't say for sure. Your actions?
A Story About Rubber Ducks and Functional Programming
Once upon a time, I wanted to get a rubber duck. One rubber duck. I spent a lot of time looking for a perfect yellow rubber duck not representing any character and finally, I have found and bought it.
Later I accidentally found a much better rubber duck. I bought it also. That's one more rubber duck than I but I wasn't cruel enough to throw first one away. A big mistake.
Sudoku Solver in Scala Part 3: Generating Cross-Dependent Test Data
This is the last part of my learnings during writing a sudoku solver. It's about several iterations of a property-based test refactoring in an attempt to find the best way to generate input data.
Sudoku Solver in Scala Part 2: Functions Compose, Methods Don’t
I keep writing about my learnings during writing a sudoku solver. This time we touch solver's logic and I have something to share about making the big functions out of the small ones.
Sudoku Solver in Scala Part 1: Validated Types
Sometimes you're trying to solve a puzzle so hard so you have to write a program to solve it. That happened to me with one specific sudoku so I wrote a sudoku solver.
I did some learning during this and I want to share them here. This part is about injecting validation into the type system.
Functional FizzBuzz in Scala With Streams and Higher Order Functions
I'm currently learning functional programming with scala and as a practice I've implemented FizzBuzz. To be honest, I made three different implementations of FizzBuzz but only the third one is good.
Stream.from(1) # Create infinite lazy stream from 1
.map { (_, "") } # convert it to (number, word) tuple
.map { x => if (x._1 % 3 == 0) (x._1, x._2 + "Fizz") else x } # Add "Fizz" to each 3rd word
.map { x => if (x._1 % 5 == 0) (x._1, x._2 + "Buzz") else x } # Add "Buzz" to each 5th word
.map { x => if (x._2 != "") x._2 else x._1.toString } # Take word or number
.take(30) # Limit stream length
.foreach(println) # Run everything and print results
It's even much better than usual imperative implementation and here's why.