Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added a map function for KoanResult

  • Loading branch information...
commit 545e38fc6b82f2115284f385000d80e1ea7f9eb3 1 parent 2e81012
Chris Marinos ChrisMarinos authored
7 FSharpKoans.Core/KoanResult.fs
@@ -10,3 +10,10 @@ with
10 10 match this with
11 11 | Success x -> x
12 12 | Failure (x, _) -> x
  13 +
  14 +[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
  15 +module KoanResult =
  16 + let map f (x:KoanResult) =
  17 + match x with
  18 + | Success m -> Success <| f m
  19 + | Failure (m, e) -> Failure (f m, e)
24 FSharpKoans.Test/KoanResults.fs
... ... @@ -0,0 +1,24 @@
  1 +module KoansRunner.Test.KoanResults
  2 +open FSharpKoans.Core
  3 +open NUnit.Framework
  4 +
  5 +[<Test>]
  6 +let ``map lets you project a message when success``() =
  7 + let result = Success "sample message"
  8 +
  9 + let mappedResult =
  10 + result
  11 + |> KoanResult.map (fun x -> x + " expanded")
  12 +
  13 + Assert.AreEqual(Success "sample message expanded", mappedResult)
  14 +
  15 +[<Test>]
  16 +let ``map lets you project a message when failure``() =
  17 + let ex = new System.Exception("abcd")
  18 + let result = Failure ("sample message", ex)
  19 +
  20 + let mappedResult =
  21 + result
  22 + |> KoanResult.map (fun x -> x + " expanded")
  23 +
  24 + Assert.AreEqual(Failure ("sample message expanded", ex), mappedResult)

0 comments on commit 545e38f

Please sign in to comment.
Something went wrong with that request. Please try again.