Skip to content

Instantly share code, notes, and snippets.

@archaeron
Created July 4, 2013 14:27
Show Gist options
  • Save archaeron/5928233 to your computer and use it in GitHub Desktop.
Save archaeron/5928233 to your computer and use it in GitHub Desktop.
map over list with options
let optionize f =
function
| None -> None
| Some(x) -> Some(f x)
let newListMap f list = List.map (optionize f) list
let listWithNull = [Some 0; Some 6; Some 3; None; Some 34; None; Some 1]
let square x = x*x
let list1 = List.map (optionize square) listWithNull
let list2 = newListMap square listWithNull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment