Created
November 24, 2012 18:52
-
-
Save adilakhter/4140927 to your computer and use it in GitHub Desktop.
f# higher order fn
This file contains 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 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