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
| List.iteri (addOne >> printfn "Current index: %i Current element: %A") ['a'..'e'] |
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
| List.iteri ((+) 1 >> printfn "Current index: %i Current element: %A") ['a'..'e'] |
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
| type ValidationResult<'a> = | |
| | Success of 'a | |
| | Error of string |
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
| open FsCheck | |
| open FsCheck.Xunit | |
| open Swensen.Unquote | |
| [<Property>] | |
| let ``tryConvertToChar converts successfully for one-character string`` () = | |
| let validStringArb = | |
| Arb.generate<char> | |
| |> Gen.map string | |
| |> Arb.fromGen |
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
| // val tryConvertToChar: s: string -> ValidationResult<char> | |
| let tryConvertToChar (s: string) = | |
| Success 'a' |
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
| open System | |
| // val tryConvertToChar: s: string -> ValidationResult<char> | |
| let tryConvertToChar (s: string) = | |
| match Char.TryParse s with | |
| | true, c -> Success c | |
| | false, _ -> Error "Input string is not a character" |
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 ``tryConvertToChar returns the same char from the one-character string`` () = | |
| let validStringArb = | |
| Arb.generate<char> | |
| |> Gen.map string | |
| |> Arb.fromGen | |
| Prop.forAll validStringArb <| fun s -> | |
| let cV = tryConvertToChar s | |
| test <@ match cV with Success c -> sprintf "%c" c = s | Error _ -> false @> |
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 ``tryConvertToChar returns error for strings with length > 2 `` () = | |
| let stringLengthLargerThan2Arb = | |
| Arb.generate<string> | |
| |> Gen.suchThat (fun s -> String.length s >= 2) | |
| |> Arb.fromGen | |
| Prop.forAll stringLengthLargerThan2Arb <| fun s -> | |
| test <@ match tryConvertToChar s with Success _ -> false | Error _ -> true @> |
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
| const http = require('http'); | |
| var i = 0, | |
| urls = [ 'http://www.google.com', 'http://www.yahoo.com' ], | |
| urlLength = urls.length; | |
| for (; i < urlLength; i++) { | |
| http.get(urls[i], function() { console.log('i: ' + i); }); | |
| } |
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
| const http = require('http'); | |
| var i = 0, | |
| urls = [ 'http://www.google.com', 'http://www.yahoo.com' ], | |
| urlLength = urls.length; | |
| for (; i < urlLength; i++) { | |
| var innerI = i; | |
| http.get(urls[i], function() { console.log('i: ' + innerI); }); | |
| } |