Advertisement
Guest User

Untitled

a guest
May 27th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. // Do something only if we actually pick a file
  2. // Use the built-in identity function as a 'T -> 'U option mapper here
  3. // for the case 'T being a FileInfo option and 'U being FileInfo
  4. let click = handler.openButton.Clicked
  5. |> Event.map (fun a -> (*
  6. open a file dialog,
  7. get a FileInfo option from the selected file name;
  8. where cancel => None *))
  9. |> Event.choose id
  10.  
  11. // Selecting an item from the menu
  12. let select =
  13. handler.openMenu.AllChildren
  14. |> Seq.cast<MenuItem>
  15. |> Seq.map (fun (i:MenuItem) -> i.Activated
  16. |> Event.map (fun a -> new FileInfo((i.Child :?> Label).Text))
  17. |> Event.filter (fun (i:FileInfo) -> i.Exists))
  18.  
  19. // The sum of all these events
  20. let accumulation = select
  21. |> Seq.fold Event.merge click
  22.  
  23. // do things with a file selection event
  24. accumulation |> Event.add UpdateRecentFileList
  25. accumulation |> Event.add LoadFile
  26. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement