This file contains hidden or 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
| /// <summary> | |
| /// Extensions to support Functional Concepts | |
| /// </summary> | |
| public static class FunctionalConcepts | |
| { | |
| /// <summary> | |
| /// Executes a given dead-end function <paramref name="f"/> on each element of the given list of <paramref name="items"/>. | |
| /// </summary> | |
| /// <typeparam name="T"></typeparam> | |
| /// <param name="items">The items.</param> |
This file contains hidden or 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 maybeThis = Maybe<This>.Just(new This()); | |
| maybeThis.Bind(@this => @this.GetMaybeThat()) | |
| .Bind(that => that.GetMaybeAnother()) | |
| .Bind(another => Maybe<AnotherThing>.Just(another)); |
This file contains hidden or 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
| if (maybeThis.IsPresent) | |
| { | |
| Maybe<That> maybeThat = maybeThis.Value.GetMaybeThat(); | |
| if (maybeThat.IsPresent) | |
| { | |
| Maybe<AnotherThing> maybeAnother = maybeThat.Value.GetMaybeAnother(); | |
| if (maybeAnother.IsPresent) | |
| { | |
| ... | |
| } |
This file contains hidden or 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
| /// <summary> | |
| /// Type to indicate that there might be a value missing. | |
| /// </summary> | |
| /// <typeparam name="TA">The type of a.</typeparam> | |
| public class Maybe<TA> | |
| { | |
| private TA _value; | |
| private bool IsPresent => _value != null; |
This file contains hidden or 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
| [Property] | |
| public Property Response_With_404_Not_Found_If_Request_Contains_UnknownId( | |
| string unknownId, | |
| string existingId) | |
| { | |
| return (HttpStatusCode.NotFound == ExerciseSendMessageWithKnownId( | |
| new Message(unknownId).WithMethod(HttpMethod.Post)).StatusCode).When(existingId != unknownId); | |
| } |
This file contains hidden or 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
| [Property] | |
| public Property Response_With_404_Not_Found_If_Request_Contains_UnknownId( | |
| string unknownId, | |
| string existingId) | |
| { | |
| // Arrange | |
| Message fixture = new Message(unknownId).WithMethod(HttpMethod.Post); | |
| // Act | |
| Response response = ExerciseSendMessageWithKnownId(existingETag); |
This file contains hidden or 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
| [Property] | |
| public Property Response_With_404_Not_Found_If_Request_Contains_UnknownId( | |
| string unknownId, | |
| string existingId) | |
| { | |
| // Arrange | |
| return new Message(unknownId) | |
| .WithMethod(HttpMethod.Post) | |
| // Act |
This file contains hidden or 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
| /// <summary> | |
| /// Extensions to support Functional Concepts | |
| /// </summary> | |
| public static class FunctionalConcepts | |
| { | |
| /// <summary> | |
| /// Pipes a given <paramref name="value"/> to given function <paramref name="f"/>. | |
| /// </summary> | |
| /// <typeparam name="TA">The type of a.</typeparam> | |
| /// <typeparam name="TB">The type of the b.</typeparam> |
This file contains hidden or 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 isValidIsbn (s : string) = | |
| let numbers = | |
| s.ToCharArray() | |
| |> Array.map (string >> int) | |
| |> List.ofArray | |
| numbers | |
| |> List.take 12 | |
| |> List.zip [ 1; 3; 1; 3; 1; 3; 1; 3; 1; 3; 1; 3; ] | |
| |> List.fold (fun result (x, y) -> result + (x * y)) 0 | |
| |> fun x -> x % 10 |
This file contains hidden or 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
| [<Property>] | |
| let ``String50 don't gets created if length isn't 50 chars`` () = | |
| Arb.generate<string> | |
| |> Gen.filter (String.length >> (<>) 50) | |
| |> Arb.fromGen | |
| |> Prop.forAll <| fun x -> | |
| None = string50 x | |
| [<Property>] | |
| let ``String50 gets created if length is 50 chars`` () = |