Created
December 4, 2016 11:36
-
-
Save teo-tsirpanis/0645e40c945217eb0fc310b701f8e01a to your computer and use it in GitHub Desktop.
An F# script that makes a list of all Pokemon and their Pokedex ID, sorted by name.
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
// An F# script that makes a list of all Pokemon and their Pokedex ID, sorted by name. | |
// Created by Theodore Tsirpanis | |
// Placed into the public domain, and licensed under CC0. | |
#r "System.Xml.Linq" | |
#r "packages/FSharp.Data/lib/net40/FSharp.Data.dll" | |
open FSharp.Data | |
open System.IO | |
[<Literal>] | |
let Url = "https://raw.githubusercontent.com/veekun/pokedex/master/pokedex/data/csv/pokemon.csv" | |
type PokemonProv = CsvProvider< Url > | |
type Pokemon = | |
{ number : int | |
name : string } | |
let prov = PokemonProv.Load(Url) | |
let Capitalize(s : string) = (s.ToUpper().[0] |> string) + s.Substring(1).ToLower() | |
let StripDashes(s : string) = s.Split([| '-' |]) |> Array.head | |
let PimpIt = Capitalize >> StripDashes | |
let pokemons = | |
prov.Rows | |
|> Seq.filter (fun row -> row.Is_default) | |
|> Seq.map (fun row -> | |
{ number = row.Id | |
name = row.Identifier }) | |
|> Seq.sortBy (fun pkmn -> pkmn.name) | |
|> Seq.map (fun pkmn -> sprintf "%s: %i" (PimpIt pkmn.name) pkmn.number) | |
File.WriteAllLines("pokemon.txt", pokemons) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment