{"action":"created","comment":{"url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/comments/199812529","pull_request_review_id":134003834,"id":199812529,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5OTgxMjUyOQ==","diff_hunk":"@@ -0,0 +1,232 @@\n+namespace UkModulusCheck\n+\n+module internal Implementation =\n+    open System\n+    open Helpers\n+    open Types\n+\n+    module Position =\n+        let U, V, W, X, Y, Z, A, B, C, D, E,  F,  G,  H =\n+            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13\n+\n+    let parseMethod = function\n+        | \"MOD10\" -> Some Standard10\n+        | \"MOD11\" -> Some Standard11\n+        | \"DBLAL\" -> Some DoubleAlternate\n+        | _ -> None\n+\n+    let parseValidationRule (line: string) =\n+        match line.Split([|' '|], StringSplitOptions.RemoveEmptyEntries) with\n+        | xs when xs.Length = 18 ->\n+            let scFrom, scTo = xs.[0], xs.[1]\n+            let method = xs.[2] |> parseMethod\n+            let weightings = xs.[3..16] |> Array.toList |> List.map str2int |> List.sequence\n+            let ex = str2int xs.[17]\n+            Option.map3 (fun m ws e ->\n+                { SortCodeFrom = scFrom; SortCodeTo = scTo; Method = m; Weightings = ws; Exception = Some (Exception e) })\n+                method weightings ex\n+        | xs when xs.Length = 17 ->\n+            let scFrom, scTo = xs.[0], xs.[1]\n+            let method = xs.[2] |> parseMethod\n+            let weightings = xs.[3..16] |> Array.toList |> List.map str2int |> List.sequence\n+            Option.map2 (fun m ws ->\n+                { SortCodeFrom = scFrom; SortCodeTo = scTo; Method = m; Weightings = ws; Exception = None })\n+                method weightings\n+        | _ -> None\n+\n+    let parseSubstitution (line: string) =\n+        match line.Split([|' '|], StringSplitOptions.RemoveEmptyEntries) with\n+        | [|scFrom; scTo|] -> Some { SortCode = scFrom; SubstituteWith = scTo }\n+        | _ -> None\n+\n+    let standardise (sortCode: string) (accountNo: string) =\n+        match sortCode.Length, accountNo.Length with\n+        | 6, 8 -> Some (sortCode, accountNo)\n+        | 6, 6 -> Some (sortCode, \"00\" + accountNo)\n+        | 6, 7 -> Some (sortCode, \"0\" + accountNo)\n+        | 6, 9 -> Some (sortCode.[0..4] + accountNo.[0..0], accountNo.[1..]) // For Santander\n+        | 6, 10 ->\n+            if sortCode.StartsWith(\"08\") // Co-Operative Bank plc\n+            then Some (sortCode, accountNo.[..7])\n+            else Some (sortCode, accountNo.[2..])\n+        | _ -> None\n+\n+    let doubleAlternateModulus (weightings: Weight list) (number: string) : int =\n+        number\n+        |> Seq.map char2int\n+        |> Seq.map2 (*) weightings\n+        |> Seq.collect (Seq.unfold (fun x -> if x > 0 then Some (x % 10, x / 10) else None))\n+        |> Seq.sum\n+\n+    let standardModulus (weightings: Weight list) (number: string) : int =\n+        number\n+        |> Seq.map char2int\n+        |> Seq.map2 (*) weightings\n+        |> Seq.sum\n+\n+    let validateRule rule number =\n+        match rule.Method with\n+        | Standard10 -> standardModulus rule.Weightings number % 10 = 0\n+        | Standard11 -> standardModulus rule.Weightings number % 11 = 0\n+        | DoubleAlternate -> doubleAlternateModulus rule.Weightings number % 10 = 0\n+\n+    let validateRules (rules: ValidationRule list) (substitutionTable: SortCodeSubstitution list) (sortCode: SortCode) (accountNo: AccountNumber) =\n+        let number = sortCode + accountNo\n+        let exceptions = rules |> List.map (fun r -> r.Exception)\n+        let isValid =\n+            match rules, exceptions with\n+            | [], _ -> true\n+\n+            | [rule], [None] ->\n+                validateRule rule number\n+\n+            | [rule1; rule2], [None; None] ->\n+                (validateRule rule1 number) && (validateRule rule2 number)\n+\n+            | [rule], [Some ex] ->\n+                match ex with","path":"src/UkModulusCheck/Implementation.fs","position":87,"original_position":87,"commit_id":"c90d846a4788a275ac234e170990f3fc9795f72a","original_commit_id":"c90d846a4788a275ac234e170990f3fc9795f72a","user":{"login":"bartsokol","id":9638275,"node_id":"MDQ6VXNlcjk2MzgyNzU=","avatar_url":"https://avatars0.githubusercontent.com/u/9638275?v=4","gravatar_id":"","url":"https://api.github.com/users/bartsokol","html_url":"https://github.com/bartsokol","followers_url":"https://api.github.com/users/bartsokol/followers","following_url":"https://api.github.com/users/bartsokol/following{/other_user}","gists_url":"https://api.github.com/users/bartsokol/gists{/gist_id}","starred_url":"https://api.github.com/users/bartsokol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartsokol/subscriptions","organizations_url":"https://api.github.com/users/bartsokol/orgs","repos_url":"https://api.github.com/users/bartsokol/repos","events_url":"https://api.github.com/users/bartsokol/events{/privacy}","received_events_url":"https://api.github.com/users/bartsokol/received_events","type":"User","site_admin":false},"body":"I've made them nested for better organisation - so it's easier to navigate between the cases, but if you think it's better to flatten it then I can change it.","created_at":"2018-07-03T13:46:03Z","updated_at":"2018-07-03T13:46:04Z","html_url":"https://github.com/transactiveltd/uk-modulus-checking/pull/2#discussion_r199812529","pull_request_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/2","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/comments/199812529"},"html":{"href":"https://github.com/transactiveltd/uk-modulus-checking/pull/2#discussion_r199812529"},"pull_request":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/2"}},"in_reply_to_id":199806766},"pull_request":{"url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/2","id":198624012,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk4NjI0MDEy","html_url":"https://github.com/transactiveltd/uk-modulus-checking/pull/2","diff_url":"https://github.com/transactiveltd/uk-modulus-checking/pull/2.diff","patch_url":"https://github.com/transactiveltd/uk-modulus-checking/pull/2.patch","issue_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues/2","number":2,"state":"open","locked":false,"title":"Initial version of the library","user":{"login":"bartsokol","id":9638275,"node_id":"MDQ6VXNlcjk2MzgyNzU=","avatar_url":"https://avatars0.githubusercontent.com/u/9638275?v=4","gravatar_id":"","url":"https://api.github.com/users/bartsokol","html_url":"https://github.com/bartsokol","followers_url":"https://api.github.com/users/bartsokol/followers","following_url":"https://api.github.com/users/bartsokol/following{/other_user}","gists_url":"https://api.github.com/users/bartsokol/gists{/gist_id}","starred_url":"https://api.github.com/users/bartsokol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartsokol/subscriptions","organizations_url":"https://api.github.com/users/bartsokol/orgs","repos_url":"https://api.github.com/users/bartsokol/repos","events_url":"https://api.github.com/users/bartsokol/events{/privacy}","received_events_url":"https://api.github.com/users/bartsokol/received_events","type":"User","site_admin":false},"body":"Contains the first two parts of the #1. There is still some cleanup in progress, some tests may be added and docs will be updated, but some feedback would be nice to see if it's close to what was expected in this library.","created_at":"2018-07-02T09:40:37Z","updated_at":"2018-07-03T13:46:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5882d6398e4835d1538491dea8c6ccc7644b948e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/2/commits","review_comments_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/2/comments","review_comment_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/comments{/number}","comments_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues/2/comments","statuses_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/statuses/c90d846a4788a275ac234e170990f3fc9795f72a","head":{"label":"transactiveltd:initial-version","ref":"initial-version","sha":"c90d846a4788a275ac234e170990f3fc9795f72a","user":{"login":"transactiveltd","id":10843006,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwODQzMDA2","avatar_url":"https://avatars0.githubusercontent.com/u/10843006?v=4","gravatar_id":"","url":"https://api.github.com/users/transactiveltd","html_url":"https://github.com/transactiveltd","followers_url":"https://api.github.com/users/transactiveltd/followers","following_url":"https://api.github.com/users/transactiveltd/following{/other_user}","gists_url":"https://api.github.com/users/transactiveltd/gists{/gist_id}","starred_url":"https://api.github.com/users/transactiveltd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/transactiveltd/subscriptions","organizations_url":"https://api.github.com/users/transactiveltd/orgs","repos_url":"https://api.github.com/users/transactiveltd/repos","events_url":"https://api.github.com/users/transactiveltd/events{/privacy}","received_events_url":"https://api.github.com/users/transactiveltd/received_events","type":"Organization","site_admin":false},"repo":{"id":138273759,"node_id":"MDEwOlJlcG9zaXRvcnkxMzgyNzM3NTk=","name":"uk-modulus-checking","full_name":"transactiveltd/uk-modulus-checking","owner":{"login":"transactiveltd","id":10843006,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwODQzMDA2","avatar_url":"https://avatars0.githubusercontent.com/u/10843006?v=4","gravatar_id":"","url":"https://api.github.com/users/transactiveltd","html_url":"https://github.com/transactiveltd","followers_url":"https://api.github.com/users/transactiveltd/followers","following_url":"https://api.github.com/users/transactiveltd/following{/other_user}","gists_url":"https://api.github.com/users/transactiveltd/gists{/gist_id}","starred_url":"https://api.github.com/users/transactiveltd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/transactiveltd/subscriptions","organizations_url":"https://api.github.com/users/transactiveltd/orgs","repos_url":"https://api.github.com/users/transactiveltd/repos","events_url":"https://api.github.com/users/transactiveltd/events{/privacy}","received_events_url":"https://api.github.com/users/transactiveltd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/transactiveltd/uk-modulus-checking","description":"Validate UK sortcode/account no. using algorithms and weights published by VocaLink","fork":false,"url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking","forks_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/forks","keys_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/keys{/key_id}","collaborators_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/teams","hooks_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/hooks","issue_events_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues/events{/number}","events_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/events","assignees_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/assignees{/user}","branches_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/branches{/branch}","tags_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/tags","blobs_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/refs{/sha}","trees_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/trees{/sha}","statuses_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/statuses/{sha}","languages_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/languages","stargazers_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/stargazers","contributors_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/contributors","subscribers_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/subscribers","subscription_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/subscription","commits_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/commits{/sha}","git_commits_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/commits{/sha}","comments_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/comments{/number}","issue_comment_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues/comments{/number}","contents_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/contents/{+path}","compare_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/compare/{base}...{head}","merges_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/merges","archive_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/downloads","issues_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues{/number}","pulls_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls{/number}","milestones_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/milestones{/number}","notifications_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/labels{/name}","releases_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/releases{/id}","deployments_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/deployments","created_at":"2018-06-22T08:02:48Z","updated_at":"2018-06-22T08:02:51Z","pushed_at":"2018-07-03T11:34:59Z","git_url":"git://github.com/transactiveltd/uk-modulus-checking.git","ssh_url":"git@github.com:transactiveltd/uk-modulus-checking.git","clone_url":"https://github.com/transactiveltd/uk-modulus-checking.git","svn_url":"https://github.com/transactiveltd/uk-modulus-checking","homepage":null,"size":112,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"transactiveltd:master","ref":"master","sha":"0059225864e35186a23c3d894917558515e9212b","user":{"login":"transactiveltd","id":10843006,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwODQzMDA2","avatar_url":"https://avatars0.githubusercontent.com/u/10843006?v=4","gravatar_id":"","url":"https://api.github.com/users/transactiveltd","html_url":"https://github.com/transactiveltd","followers_url":"https://api.github.com/users/transactiveltd/followers","following_url":"https://api.github.com/users/transactiveltd/following{/other_user}","gists_url":"https://api.github.com/users/transactiveltd/gists{/gist_id}","starred_url":"https://api.github.com/users/transactiveltd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/transactiveltd/subscriptions","organizations_url":"https://api.github.com/users/transactiveltd/orgs","repos_url":"https://api.github.com/users/transactiveltd/repos","events_url":"https://api.github.com/users/transactiveltd/events{/privacy}","received_events_url":"https://api.github.com/users/transactiveltd/received_events","type":"Organization","site_admin":false},"repo":{"id":138273759,"node_id":"MDEwOlJlcG9zaXRvcnkxMzgyNzM3NTk=","name":"uk-modulus-checking","full_name":"transactiveltd/uk-modulus-checking","owner":{"login":"transactiveltd","id":10843006,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwODQzMDA2","avatar_url":"https://avatars0.githubusercontent.com/u/10843006?v=4","gravatar_id":"","url":"https://api.github.com/users/transactiveltd","html_url":"https://github.com/transactiveltd","followers_url":"https://api.github.com/users/transactiveltd/followers","following_url":"https://api.github.com/users/transactiveltd/following{/other_user}","gists_url":"https://api.github.com/users/transactiveltd/gists{/gist_id}","starred_url":"https://api.github.com/users/transactiveltd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/transactiveltd/subscriptions","organizations_url":"https://api.github.com/users/transactiveltd/orgs","repos_url":"https://api.github.com/users/transactiveltd/repos","events_url":"https://api.github.com/users/transactiveltd/events{/privacy}","received_events_url":"https://api.github.com/users/transactiveltd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/transactiveltd/uk-modulus-checking","description":"Validate UK sortcode/account no. using algorithms and weights published by VocaLink","fork":false,"url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking","forks_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/forks","keys_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/keys{/key_id}","collaborators_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/teams","hooks_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/hooks","issue_events_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues/events{/number}","events_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/events","assignees_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/assignees{/user}","branches_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/branches{/branch}","tags_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/tags","blobs_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/refs{/sha}","trees_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/trees{/sha}","statuses_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/statuses/{sha}","languages_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/languages","stargazers_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/stargazers","contributors_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/contributors","subscribers_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/subscribers","subscription_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/subscription","commits_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/commits{/sha}","git_commits_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/git/commits{/sha}","comments_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/comments{/number}","issue_comment_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues/comments{/number}","contents_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/contents/{+path}","compare_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/compare/{base}...{head}","merges_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/merges","archive_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/downloads","issues_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues{/number}","pulls_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls{/number}","milestones_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/milestones{/number}","notifications_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/labels{/name}","releases_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/releases{/id}","deployments_url":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/deployments","created_at":"2018-06-22T08:02:48Z","updated_at":"2018-06-22T08:02:51Z","pushed_at":"2018-07-03T11:34:59Z","git_url":"git://github.com/transactiveltd/uk-modulus-checking.git","ssh_url":"git@github.com:transactiveltd/uk-modulus-checking.git","clone_url":"https://github.com/transactiveltd/uk-modulus-checking.git","svn_url":"https://github.com/transactiveltd/uk-modulus-checking","homepage":null,"size":112,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/2"},"html":{"href":"https://github.com/transactiveltd/uk-modulus-checking/pull/2"},"issue":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues/2"},"comments":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/transactiveltd/uk-modulus-checking/statuses/c90d846a4788a275ac234e170990f3fc9795f72a"}},"author_association":"NONE"}}
{"actor":{"display_login":"bartsokol"}}