Browse Source

Began removing the if statements to pattern matching in lib.

Wrote a quick test command-method without a try-catch block to see how it would react. Pondering the removal of all the try-catch blocks in the console program.
master
Craig Oates 6 years ago
parent
commit
9a1496b0c5
  1. 38
      WetPancake/ProductServices.fs
  2. 5
      WetPancakeCLI/ConsoleCommands.cs

38
WetPancake/ProductServices.fs

@ -72,4 +72,42 @@ module Pancake =
ListSampleFiles
|> Array.toList
return files
}
// ===================================================================
let gibCheck g =
match g with
| g when g < 2 || g > 20 ->
raise (ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel"))
| _ -> ignore
let senCheck s =
match s with
| s when s < 1 ->
raise (ArgumentException("Invalid argument. Must be greater than 0.", "sentences"))
| _ -> ignore
// TEST FUNCTION
let RequestTest (gibberishLevel: int) (sentences: int) =
async {
try
gibCheck gibberishLevel |> ignore
senCheck sentences |> ignore
let data =
LoadFile (SelectRandomSampleFile())
|> ApplyStandardSetup
|> SortIntoGroups gibberishLevel
|> GenerateMap
return GenerateMarkovText sentences data
(*
else
return raise (ArgumentException("Invalid argument. Must be greater than 0.", "sentences"))
else
return raise (ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel"))
*)
with
| :? ArgumentException as ex ->
return ex.Message
}

5
WetPancakeCLI/ConsoleCommands.cs

@ -113,5 +113,10 @@ namespace WetPancakeCLI
throw;
}
}
public static string failtest(int gibberishLevel, int sentences)
{
return FSharpAsync.StartAsTask(RequestTest(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
}
}
}

Loading…
Cancel
Save