type Direction = Up | Down
type BoxTree<'Item> =
| Item of 'Item
| BoxSet of BoxTree<'Item> list * Direction
let rec (|Split|_|) fnCheck tree =
match tree with
| BoxSet (a::b::[],dir) when fnCheck a ->
Split (a,b,dir) |> Some
| BoxSet (_,_)
| Item _ ->
None
let tryFindSplitOnItem checkFn tree =
| Split checkFn box -> Some(box)
| _ -> None