Skip to content

Instantly share code, notes, and snippets.

module Tests
open Xunit
open Swensen.Unquote
open Monad
[<Fact>]
let ``Maybe bind on Just`` () =
Just 5 >>= (((*) 10) >> return') =! Just 50
module Monad
/// Maybe (Option)
type Maybe<'a> =
| Nothing
| Just of 'a
static member inline doReturn (v) = Just v
static member inline doReturnFrom (v) = v
@cowlike
cowlike / KotlinTest.kt
Last active March 13, 2018 15:22
Simple testing with Kotlin
fun doTests() {
// println("run test 1")
// runTest(::test1)
println("\nrun test 2")
runTest(::test2)
println("\nrun test 3")
runTest(::test3)
}
static bool isArmstrong(int n) {
var digits = n.ToString().Select(x => (int)(x - '0'));
return n == digits.Select(x => (int)Math.Pow(x, digits.Count())).Sum();
}
fun mkCycle(min: Int, max: Int) = generateSequence(min) {
if (it < max) it + 1 else min
}
@cowlike
cowlike / GenerateFibonacci.fs
Created January 23, 2018 22:14
Unfold ftw...
let fibos = Seq.unfold (fun (x, y) -> Some(y, (y, x + y))) (0, 1)
@cowlike
cowlike / GeneratePrimes.kt
Created January 21, 2018 16:04
Kotlin prime number generation
import kotlin.coroutines.experimental.buildIterator
import kotlin.coroutines.experimental.buildSequence
///not tail recursive!
fun primes(n: Int = 2): Sequence<Int> = buildSequence<Int> {
yield(n)
yieldAll(primes(n + 1).filter { x: Int -> x % n != 0 })
}
///tail recursive version
@cowlike
cowlike / Util.fs
Created January 8, 2018 20:51
Some utilities & howto
module Util
open System
open System.Collections.Generic
let toGenericList lst = List<_>(List.toSeq lst)
let env =
let envVars =
Environment.GetEnvironmentVariables()
@cowlike
cowlike / demo.md
Last active January 8, 2018 12:58
Demo dotnet app with Docker

Demo dotnet app with Docker

Create an app:

dotnet new console -o myApp
cd myApp/
dotnet publish -o publish -r linux-x64
# add Dockerfile
docker build . -t myapp:latest
@cowlike
cowlike / random.kt
Created January 5, 2018 21:32
Random Kotlin stuff
fun <K> HashMap<K,String>.build() {
for (i in this.keys) {
val x = i.toString()
this.put(i, x)
}
}
/*
fun HashMap<Int,String>.build() {
this.put(0, "0")