Skip to content

Instantly share code, notes, and snippets.

@wallymathieu
Created September 25, 2015 20:10
Show Gist options
  • Select an option

  • Save wallymathieu/dda0eca33a18f5d07290 to your computer and use it in GitHub Desktop.

Select an option

Save wallymathieu/dda0eca33a18f5d07290 to your computer and use it in GitHub Desktop.
stitch
let r = [0;1;2;3]
let stitch s=
let head = s |> Seq.head
let tail = s |> Seq.skip 1
tail |> Seq.scan (fun state elem-> (snd state, elem)) (head, head)
|> Seq.skip 1
|> Seq.toList
open System.Linq
let stitch_and_end (s: 'a seq) (last: 'a) =
let stitched = stitch s
let e = Enumerable.Last s
stitched @ [(e, last)]
stitch r
stitch_and_end r -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment