This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Anything you type in here will be executed | |
;; immediately with the results shown on the | |
;; right. | |
(def data '({:name "nick" :age 20} {:name "george", :age 30} | |
{:name "giannis", :age 40} {:name "dimitris", :age 50})) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#time | |
#r "bin/Release/Streams.Core.dll" | |
open Nessos.Streams.Core | |
let data = [|1..10000000|] |> Array.map int64 | |
#r "../../packages/FSharp.Collections.ParallelSeq.1.0/lib/net40/FSharp.Collections.ParallelSeq.dll" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#time | |
#r "bin/Release/Streams.Core.dll" | |
open Nessos.Streams.Core | |
let rnd = new System.Random() | |
let data = [|1..10000000|] |> Array.map (fun _ -> int64 <| rnd.Next(1000000)) | |
#r "../../packages/FSharp.Collections.ParallelSeq.1.0/lib/net40/FSharp.Collections.ParallelSeq.dll" | |
open FSharp.Collections.ParallelSeq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#time | |
#r "bin/Release/Streams.Core.dll" | |
open Nessos.Streams.Core | |
let data = [|1..10000000|] |> Array.map (fun i -> int64 <| (i % 1000000)) | |
#r "../../packages/FSharp.Collections.ParallelSeq.1.0/lib/net40/FSharp.Collections.ParallelSeq.dll" | |
open FSharp.Collections.ParallelSeq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Grouping<'T> = { IndexRef : int ref; ArrayRef : 'T [] ref } | |
let rec groupingAdd (value : 'T) (grouping : Grouping<'T>) = | |
let indexRef = grouping.IndexRef | |
let arrayRef = grouping.ArrayRef | |
let array = !arrayRef | |
if Object.ReferenceEquals(array, null) then | |
groupingAdd value grouping | |
else | |
let index = Interlocked.Increment(indexRef) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#time | |
let sum (f : 'T -> int -> int) (array : 'T[]) = | |
let mutable sum = 0 | |
for i = 0 to array.Length - 1 do | |
sum <- sum + f array.[i] i | |
sum | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Stream<'T> = ('T -> unit) -> unit -> bool | |
let inline ofArray (source : 'T []) : Stream<'T> = | |
fun iterf -> | |
let i = ref 0 | |
fun () -> | |
let flag = !i < source.Length | |
if not flag then | |
false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#time "on" | |
let inline readAllHashes nSkip nSentences = | |
sentencesFile | |
|> File.ReadLines | |
|> Stream.ofSeq | |
|> Stream.skip nSkip | |
|> Stream.take nSentences | |
|> Stream.map(fun line -> | |
let separatorIndex = line.IndexOf(' ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Bool = interface end | |
and True = True with | |
interface Bool | |
and False = False with | |
interface Bool | |
type And = And with | |
static member inline (?<-) (True, And, True) = True | |
static member inline (?<-) (True, And, False) = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int foo() | |
{ | |
auto flatMap = [](auto f, auto s) { return [=](auto k) { return s([=](auto x) { f(x)(k); }); }; }; | |
auto map = [](auto f, auto s) { return [=](auto k) { s([=](auto x) { k(f(x)); }); }; }; | |
auto filter = [](auto p, auto s) { return [=](auto k) { s([=](auto x) { if(p(x)) k(x); }); }; }; | |
auto sum = [](auto k) { int sum = 0; k([&](int x) { sum += x; }); return sum; }; |