As part of my F# journey, I came to the idea to explore data provided by the World Bank. The follow F# code fetches Diesel prices in USD per liter.
These compontens have been used:
|WorldBank Type Provider||This provider enables the access to the World Banks data in a type-safe way. The beauty about F# type providers is that they take care of basically everything you need for the communcation to an external system. In my demo here, I didn’t not generate any service proxy representing World Banks API. But the IDE still provided me full IntelliSense support.|
|F# Charting||Charting library for F#.|
It took my a while to figure out how to write the code in a functional manner. But as you can see, the code is easy to read. First it loads Diesel prices by country (Switzerland, Norway, United States and Saudi Arabia), adds each identicator to the chart and plots it in the end.
open FSharp.Data open FSharp.Charting [<EntryPoint>] let main argv = let bank = WorldBankData.GetDataContext() let countries = [| bank.Countries.Switzerland bank.Countries.Norway bank.Countries.``United States`` bank.Countries.``Saudi Arabia`` |] [ for c in countries -> c.Indicators.``Pump price for diesel fuel (US$ per liter)`` ] |> List.map (fun i -> Chart.Line(i, i.Code)) |> Chart.Combine |> Chart.WithLegend true |> Chart.Show 0
The end result looks like this.