Skip to content

Instantly share code, notes, and snippets.

View PointOfSaleTerminal.fs
namespace Terminal
open System
open System.Collections.Immutable
[<Measure>] type USD
[<Measure>] type Volume
[<Measure>] type Percent
type Price =
akimboyko / problem17.fsx
Created May 4, 2014
Count number of letters written out in words without spaces or hyphens using F# and Humanizer
View problem17.fsx
#r @"Humanizer.dll"
open Humanizer
[1 .. 1000] |> (fun n -> Humanizer.NumberToWordsExtension.ToWords(n)) |>
Seq.collect(fun writtenOutInWords -> writtenOutInWords.ToCharArray()) |>
Seq.where(fun ch -> ch <> ' ') |>
Seq.where(fun ch -> ch <> '-') |>
akimboyko / FsCheckSamples.fsx
Last active Mar 27, 2019
Samples for Property-based testing using FsCheck for F# and C# talk for Kiev Alt.NET
View FsCheckSamples.fsx
#I @".\packages\FsCheck.\lib\net40-Client\"
#r @"FsCheck.dll"
// #time "on"
open FsCheck
// simple example
let revRevIsOrig (xs:list<int>) = List.rev(List.rev xs) = xs
Check.Quick revRevIsOrig;;

Toy Problem: Missionaries and Cannibals


On one bank of a river are three missionaries (black triangles) and three cannibals (red circles). There is one boat available that can hold up to two people and that they would like to use to cross the river. If the cannibals ever outnumber the missionaries on either of the river’s banks, the missionaries will get eaten. How can the boat be used to safely carry all the missionaries and cannibals across the river?


Try to implement the general search algorithm just described. You can use LIFO and FIFO as queuing strategies to determine the order in which nodes are explored. These two strategies are known as depth-first and breadth-first search respectively. Be careful, depth-first search may descend down infinite branches, so best implement a depth cut-off. Then, extend your implementation with a hash table that stores all the nodes found so far. Print out a trace of the states the algorithm finds (in the order they are discovered) and see ho

View gist:8584781
public static class EnumerableEx
public static IEnumerable<R> Select<T1, T2, R>(this IEnumerable<Tuple<T1, T2>> source, Func<T1, T2, R> f)
return source.Select(t => f(t.Item1, t.Item2));
Enumerable.Range(1, 10)
.Select(x => Tuple.Create(x, x))
akimboyko / DI_patterns.fs
Created Jan 12, 2014
DI patterns from Scala adopted to F#: structural typing and currying
View DI_patterns.fs
// Inspired by Scala and
type Cell() =
override m.ToString() = "*"
type IGameOfLife =
abstract member Next: IGameOfLife
abstract member Generation : seq<Cell>
// Types for Structural Typing
akimboyko / quotes.txt
Last active Jan 5, 2016 — forked from mausch/gist:8227399
Quotes by Erik Meijer from Reactive programming course
View quotes.txt
"Hopefully the third answer is right; but who knows, maybe I made a mistake; I’m just a human, I can throw exceptions as well."
"I am waving my hands on purpose here, this is very spaghetti like code. And spaghetti is great as food, but not good as code."
"flatMap will allow us to focus on the happy path. flatMap will take care of all the noise. flatMap is the dolby for programmers."
"Great programmers write baby code"
"it's obviously correct"
akimboyko / BinaryTreeCheck.scala
Created Dec 22, 2013
Properties proved by ScalaCheck about BinaryTree from Reactive course week #005
View BinaryTreeCheck.scala
package actorbintree
import scala.concurrent.duration._
import{Props, ActorSystem}
import akka.testkit._
import org.scalacheck.{Gen, Properties}
import org.scalacheck.Prop._
import actorbintree.BinaryTreeSet._
import actorbintree.BinaryTreeSet.Contains
import actorbintree.BinaryTreeSet.OperationFinished
akimboyko / GameOfLife.scala
Created Dec 15, 2013
Game of Life implemented on Scala during Global Day of Coderetreat 2013 at Kiev
View GameOfLife.scala
object GameOfLife {
// data structure
class Cell(x: Int, y: Int) {
val posX = x
val posY = y
override def toString = "Cell: " + x + "," + y
akimboyko /
Created Dec 5, 2013
Why is Future.always useful? Why would I use it if its value is already precomputed?

Future.always is a way to lift a normal value T to a Future[T] value. This lifting pattern is something you will see often in functional programming, so remember it well!

To make its usefulness more apparent - imagine that your API method should either call some Web service or look in the cached responses to see if the Web service was already queried with that request. In the first case you have to return a future Future[String] of a response, and in the second you need to return a response String right away from your cache. Future.always can help you solve this tricky type situation.