Advertisement
Guest User

Untitled

a guest
Jul 17th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.66 KB | None | 0 0
  1. type toDo = {id: string; indent: int; descendants: toDo list}
  2.  
  3. let rec children x ys accumulated =
  4.         match ys with
  5.             | [] -> (accumulated, [])
  6.             | y::rest ->
  7.                 match (y.indent - x.indent) with
  8.                     | 1 ->
  9.                         let descendants, _ = children y rest List.empty<toDo>
  10.                         let filledChild = {y with descendants = descendants |> List.sortBy (fun x -> x.id)}
  11.                         filledChild::accumulated |> children x rest
  12.                     | diff when diff < 1 -> (accumulated |> List.sortBy(fun x -> x.id), y::rest)
  13.                     | _ -> children x rest accumulated
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement