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
type myStorageAccount = Elastacloud.FSharp.AzureTypeProvider.AzureAccount< "AccountName", "AccountKey"> | |
// Get all Fulham players, get the name cost, sorting in value | |
myStorageAccount.Tables.Players.GetPartition("Fulham") | |
|> Seq.map(fun player -> player.Name, player.Cost) | |
|> Seq.sortBy snd | |
|> Seq.toArray | |
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
/// A sample map reducer that counts words in a document. Notice how the outputs of both map and reduce do not have to be strings. | |
module HadoopFs.Samples.WordCount | |
open System | |
/// A sample mapper that splits lines based on spaces into words and counts the number of occurences within a line. | |
let Mapper (row : string) = | |
row.Split([| ' ' |], StringSplitOptions.RemoveEmptyEntries) | |
|> Seq.countBy id | |
/// A sample reducer that counts words supplied from the word count mapper. |
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
/// A mapper exe | |
let mainMap argv = | |
doMap <| ManyOutputs WordCount.Mapper | |
0 | |
/// A reducer exe | |
let mainReduce argv = | |
doReduce <| SingleOutput WordCount.Reducer | |
0 |
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
/// The different types of outcomes an aspect can have | |
type AspectResult<'TInput, 'TOutput> = | |
| ContinueWith of 'TInput | |
| ErrorOf of Exception | |
| ReturnWith of 'TOutput | |
/// The signature that any aspect has | |
type Aspect<'TInput, 'TOutput> = 'TInput -> AspectResult<'TInput, 'TOutput> |
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
// Function that we will decorate | |
let add (first, second) = first + second | |
/// Prints the provided arguments to the console and passes control to the next item in the pipeline | |
let printArgsAspect args = | |
printfn "in print!" | |
printfn "arguments are: %A" args | |
ContinueWith args | |
/// Returns an error if the secondary value is zero, otherwise continues |
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
/// Connects two aspects to one another | |
let boltAspect aspect aspectResult = | |
match aspectResult with | |
| ContinueWith args -> | |
printfn "continuing" | |
aspect args | |
| _ -> | |
printfn "prematurely exiting" | |
aspectResult |
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
// Construct add with three aspects | |
let addWithAspects = | |
stopDivideByZeroAspect | |
>> boltAspect postiveOnlyAspect | |
>> boltAspect printArgsAspect | |
>> closeBolt add | |
// Call the "composed" add - has the same signature as the original add function | |
addWithAspects(10,15) |
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
/// Bolt two aspects together. | |
let (->>) x y = x >> boltAspect y | |
/// Bolts an aspect to a function. | |
let (>>!) x y = x >> closeBolt y | |
let addWithAspects = stopDivideByZeroAspect ->> postiveOnlyAspect ->> printArgsAspect >>! add | |
addWithAspects(0, 10) | |
(* |
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
try | |
{ | |
Foo.Bar(); | |
} | |
catch (System.IO.FileLoadException) | |
{ | |
Console.WriteLine("File load exception!"); | |
} | |
catch (System.Net.HttpListenerException ex) | |
{ |
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
var numbers = Foo.GetNumbers(); | |
if (numbers.Length == 2 && numbers[0] == 7) | |
{ | |
var second = numbers[1]; | |
Console.WriteLine("7,{1}", second); | |
} | |
else if (numbers.Length == 2) | |
{ | |
var first = numbers[0]; |
OlderNewer