Created
December 9, 2014 21:50
Revisions
-
Philip Joseph created this gist
Dec 9, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,73 @@ /* @flow */ var T = require('immutable'); type Branch = T.List<string> type TrainLine = T.Map<string, Branch> type CTAMap = T.Map<string, TrainLine> /* * Representation of Chicago's train stops and branches */ var ctaMap: CTAMap = new T.Map(); var blueLine: TrainLine = new T.Map().set("O'Hare Branch", T.List.of( "O'Hare", "Rosemont", "Cumberland", "Harlem", "Jefferson Park", "Montrose", "Irving Park", "Addison", "Belmont", "Logan Square", "California", "Western", "Damen" ) ).set("Milwaulkee-Dearborn Subway", T.List.of( "Division", "Chicago", "Grand", "Clark / Lake", "Washington", "Monroe", "Jackson", "LaSalle", "Clinton" ) ).set("Forest Park 'Congress' Branch", T.List.of( "UIC-Halsted", "Racine", "Illinois Medical Center", "Western", "Kedzie-Homan", "Pulaski", "Cicero", "Austin", "Oak Park", "Harlem", "Forest Park" ) ); ctaMap = ctaMap.set('blue', blueLine); // ERROR: call of method count // Method cannot be called on optional of Branch var numStops: number = blueLine.toSeq().reduce((r, n) => r + n.count(), 0); // ERROR: call of method count // Method cannot be called on optional of Branch var numStopsByBranch = blueLine.map((v, k) => v.count()); console.log("The CTA Blue Line has " + numStops + " stops.") // => The CTA Blue Line has 33 stops. console.log(numStopsByBranch); // => Map { O'Hare Branch: 13, Milwaulkee-Dearborn Subway: 9, Forest Park 'Congress' Branch: 11 }