Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added a map function for KoanResult

  • Loading branch information...
commit 545e38fc6b82f2115284f385000d80e1ea7f9eb3 1 parent 2e81012
Chris Marinos ChrisMarinos authored
Showing with 31 additions and 0 deletions.
  1. +7 −0 FSharpKoans.Core/KoanResult.fs
  2. +24 −0 FSharpKoans.Test/KoanResults.fs
7 FSharpKoans.Core/KoanResult.fs
View
@@ -10,3 +10,10 @@ with
match this with
| Success x -> x
| Failure (x, _) -> x
+
+[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
+module KoanResult =
+ let map f (x:KoanResult) =
+ match x with
+ | Success m -> Success <| f m
+ | Failure (m, e) -> Failure (f m, e)
24 FSharpKoans.Test/KoanResults.fs
View
@@ -0,0 +1,24 @@
+module KoansRunner.Test.KoanResults
+open FSharpKoans.Core
+open NUnit.Framework
+
+[<Test>]
+let ``map lets you project a message when success``() =
+ let result = Success "sample message"
+
+ let mappedResult =
+ result
+ |> KoanResult.map (fun x -> x + " expanded")
+
+ Assert.AreEqual(Success "sample message expanded", mappedResult)
+
+[<Test>]
+let ``map lets you project a message when failure``() =
+ let ex = new System.Exception("abcd")
+ let result = Failure ("sample message", ex)
+
+ let mappedResult =
+ result
+ |> KoanResult.map (fun x -> x + " expanded")
+
+ Assert.AreEqual(Failure ("sample message expanded", ex), mappedResult)
Please sign in to comment.
Something went wrong with that request. Please try again.