Skip to content

Instantly share code, notes, and snippets.

@adilakhter
Created November 24, 2012 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adilakhter/4140927 to your computer and use it in GitHub Desktop.
Save adilakhter/4140927 to your computer and use it in GitHub Desktop.
f# higher order fn
let names = ["alice"; "bob"; "carol"]
let name = List.tryFind (fun s -> length s < 4) names
match name with
| Some n -> printfn "%s" n
| None -> printfn "They all have long names"
// partial application
let doubled = Seq.map (fun v -> v *2) values
// isDivisibleBy
let isDivisibleBy x y = y % x = 0
let evens = List.filter (isDivisibleBy 2) values // rather than (fun v -> isDivisibleBy 2 v)
// takes a predicate, return a fn:
// val it: 'a list -> 'a list
let except f = List.filter (not << f)
let numerics = List.filter isNumeric someList // returns another list
> List.filter
var f = evaluator.makeEval (expressionText);
foreach (var variableAssignment in allVariableAssigntments){
var result = f.Invoke(variableAssignment);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment