Skip to content

Instantly share code, notes, and snippets.

@teo-tsirpanis
Created December 4, 2016 11:36
Show Gist options
  • Save teo-tsirpanis/0645e40c945217eb0fc310b701f8e01a to your computer and use it in GitHub Desktop.
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.
// 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