Created
April 16, 2009 05:29
-
-
Save mattpodwysocki/96242 to your computer and use it in GitHub Desktop.
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
#light | |
[<AutoOpen>] | |
module Operators = | |
let (||>) (x,y) f = f x y | |
module Map = | |
let union m1 m2 = | |
(m1, m2) ||> Map.fold_right Map.add | |
let of_listWith (f:'a -> 'a -> 'a) (l:('key * 'a) list) : Map<'k, 'a> = | |
(l, Map.empty) ||> List.fold_right | |
(fun (k, v) acc -> | |
match Map.tryfind k acc with | |
| None -> Map.add k v acc | |
| Some x -> Map.add k (f x v) acc) | |
let singleton k v = | |
Map.add k v Map.empty | |
let transformPrefs (m:Map<string, Map<string, float>>) = | |
Map.to_list m | |
|> List.map_concat (fun (x, y) -> [for (a, b) in Map.to_list y -> (a, Map.singleton x b)]) | |
|> Map.of_listWith Map.union |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment