Created
September 8, 2015 04:22
-
-
Save talesin/7ab8b0bcee13811c7d6b to your computer and use it in GitHub Desktop.
First pass of tree based subset check go two JSON objects
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
| let rec flatten (token:JToken) = [ | |
| if token = null then | |
| () | |
| else if not token.HasValues then | |
| yield (token.Path, token.Type, string token) | |
| yield! flatten token.Next | |
| else | |
| yield! flatten token.First | |
| yield! flatten token.Next | |
| ] | |
| let truncPath (basePath:string) (path:string) = | |
| path.Remove(0, basePath.Length+1) | |
| let truncPathAll path tokens = | |
| tokens | |
| |> List.map (fun (k, t, v) -> (k |> truncPath path, t, v)) | |
| let compareTo token2 token1 = | |
| token1 | |
| |> List.map (fun (k1, t1, v1) -> | |
| let kvt2 = token2 |> List.tryFind (fun (k2, t2, v2) -> k1 = k2) | |
| let same = kvt2.IsSome && match kvt2 with | Some (_, t2, v2) -> t1 = t2 && v1 = v2 | None -> false | |
| ((k1, t1, v1), kvt2, same)) | |
| |> List.filter (fun (_, _, x) -> not x) | |
| |> List.map (fun (x1, x2, _) -> (x1, x2)) | |
| let isSubsetOf t1 t2 = | |
| t1 |> List.forall (fun e1 -> t2 |> List.exists (fun e2 -> e1 = e2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment