fork download
  1. type Government = {
  2. Id : int;
  3. Name : string;
  4. Abbreviation : string;
  5. ParentId : string option;
  6. }
  7.  
  8. type GovernmentStructure<'gov> =
  9. | Root of Government : 'gov * GovernmentStructure<'gov> list
  10. | Node of Government : 'gov * GovernmentStructure<'gov> list
  11. | Leaf of Government : 'gov
  12.  
  13. let rec findGovernment (gov : Government)
  14. (governmentStructure : GovernmentStructure<Government> list) =
  15. [
  16. for x in governmentStructure do
  17. match x with
  18. | Root(gov', subGov) ->
  19. if gov = gov' then yield gov' else yield findGovernment gov subGov
  20. | Node(gov', subGov) ->
  21. if gov = gov' then yield gov' else yield findGovernment gov subGov
  22. | Leaf(gov') ->
  23. if gov = gov' then yield gov'
  24. ] |> List.head
Success #stdin #stdout 0s 29016KB
stdin
Standard input is empty
stdout
Standard output is empty