simple-pairs
simple pair implementation in Javascript
Usage
// [User]var users = id: 1 name: 'userA' id: 2 name: 'userB' id: 3 name: 'userC' ; // [Photo]var photos = userId: 1 photo: ' :) ' userId: 3 photo: ' :( ' userId: 2 photo: ' :-) ' userId: 2 photo: ' :-/ ' ; var Pair = Pair;var Pairs = Pairs;var R = ; // Photo -> User? -> PhotoWithUservar { return userId: photouserId username: user ? username : null photo: photophoto ;}; // [{ userId: UserId, photo: String, name: String }]var photosWithMap = ; var { // Map UserId User var indexMap = R; return R;};
API
Pair.make :: a -> b -> Pair a bPair.first :: Pair a b -> aPair.second :: Pair a b -> bPair.mapFirst :: (a -> c) -> Pair a b -> Pair c bPair.mapSecond :: (b -> c) -> Pair a b -> Pair a cPair.swap :: Pair a b -> Pair b a Pairs.fromMap :: Map a b -> [Pair a b]Pairs.toMap :: [Pair a b] -> Map a b