{"id":19115380,"url":"https://github.com/polytypic/pprint","last_synced_at":"2025-04-19T00:32:45.420Z","repository":{"id":16704276,"uuid":"19461020","full_name":"polytypic/PPrint","owner":"polytypic","description":null,"archived":false,"fork":false,"pushed_at":"2018-03-02T14:26:29.000Z","size":171,"stargazers_count":3,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-04T03:36:51.828Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://polytypic.github.io/PPrint/PPrint.html","language":"F#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polytypic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-05T15:39:52.000Z","updated_at":"2020-02-20T10:34:58.000Z","dependencies_parsed_at":"2022-07-12T15:14:28.805Z","dependency_job_id":null,"html_url":"https://github.com/polytypic/PPrint","commit_stats":null,"previous_names":["vesakarvonen/pprint"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2FPPrint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2FPPrint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2FPPrint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2FPPrint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polytypic","download_url":"https://codeload.github.com/polytypic/PPrint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223786797,"owners_count":17202603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T04:46:13.433Z","updated_at":"2024-11-09T04:46:14.681Z","avatar_url":"https://github.com/polytypic.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"PPrint is a pretty printing combinator library for text documents that can be\nrendered to a desired maximum width.\n\n### Docs\n\n* [PPrint reference](http://polytypic.github.io/PPrint/PPrint.html)\n  * [![NuGet](https://img.shields.io/nuget/v/PPrint.svg)](https://www.nuget.org/packages/PPrint/) [![NuGet total](https://img.shields.io/nuget/dt/PPrint.svg)](https://www.nuget.org/packages/PPrint/)\n* [PPrint.Console reference](http://polytypic.github.io/PPrint/PPrint.Console.html)\n  * [![NuGet](https://img.shields.io/nuget/v/PPrint.Console.svg)](https://www.nuget.org/packages/PPrint.Console/) [![NuGet total](https://img.shields.io/nuget/dt/PPrint.Console.svg)](https://www.nuget.org/packages/PPrint.Console/)\n\n### Background\n\n* [A prettier printer](http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf)\n* [PPrint, a prettier printer](http://research.microsoft.com/en-us/um/people/daan/download/pprint/pprint.html)\n\n### Example\n\nHere is an example of how one could define a function with signature\n\n```fsharp\nmodule Json =\n  val pretty: JsonValue -\u003e Doc\n```\n\nfor pretty printing JSON values:\n\n```fsharp\nopen System.Json\nopen PPrint\n\nlet inline (^) x = x\n\nmodule Json =\n  let private prettySeq (l, r) toDoc xs =\n    if Seq.isEmpty xs\n    then l \u003c^\u003e r\n    else let ds = xs |\u003e Seq.map toDoc |\u003e punctuate comma |\u003e vsep\n         l \u003c..\u003e ds |\u003e nest 2 \u003c..\u003e r |\u003e group\n\n  let rec pretty (json: JsonValue) =\n    match json with\n     | :? JsonObject as json -\u003e\n       json\n       |\u003e prettySeq lrbrace ^ fun kv -\u003e\n            pretty ^ JsonPrimitive kv.Key \u003c^\u003e colon \u003c+\u003e pretty kv.Value\n     | :? JsonArray as json -\u003e\n       json\n       |\u003e prettySeq lrbracket pretty\n     | null -\u003e\n       txt \"null\"\n     | _ -\u003e\n       json\n       |\u003e string\n       |\u003e txt\n```\n\nGiven a JSON value\n\n```fsharp\nlet json = JsonValue.Parse \"\"\"\n{\n  \"firstName\": \"John\",\n  \"lastName\": \"Smith\",\n  \"isAlive\": true,\n  \"age\": 25,\n  \"address\": {\n    \"streetAddress\": \"21 2nd Street\",\n    \"city\": \"New York\",\n    \"state\": \"NY\",\n    \"postalCode\": \"10021-3100\"\n  },\n  \"phoneNumbers\": [\n    {\n      \"type\": \"home\",\n      \"number\": \"212 555-1234\"\n    },\n    {\n      \"type\": \"office\",\n      \"number\": \"646 555-4567\"\n    }\n  ],\n  \"children\": [],\n  \"spouse\": null\n}\n\"\"\"\n```\n\nwe can render it to different desired maximum widths.  For example,\n\n```fsharp\njson |\u003e Json.pretty |\u003e println ^ Some 40\n```\n\nproduces\n\n```\n{\n  \"address\": {\n    \"city\": \"New York\",\n    \"postalCode\": \"10021-3100\",\n    \"state\": \"NY\",\n    \"streetAddress\": \"21 2nd Street\"\n  },\n  \"age\": 25,\n  \"children\": [],\n  \"firstName\": \"John\",\n  \"isAlive\": true,\n  \"lastName\": \"Smith\",\n  \"phoneNumbers\": [\n    {\n      \"number\": \"212 555-1234\",\n      \"type\": \"home\"\n    },\n    {\n      \"number\": \"646 555-4567\",\n      \"type\": \"office\"\n    }\n  ],\n  \"spouse\": null\n}\n```\n\nand\n\n```fsharp\njson |\u003e Json.pretty |\u003e println ^ Some 80\n```\n\nproduces\n\n```\n{\n  \"address\": {\n    \"city\": \"New York\",\n    \"postalCode\": \"10021-3100\",\n    \"state\": \"NY\",\n    \"streetAddress\": \"21 2nd Street\"\n  },\n  \"age\": 25,\n  \"children\": [],\n  \"firstName\": \"John\",\n  \"isAlive\": true,\n  \"lastName\": \"Smith\",\n  \"phoneNumbers\": [\n    {\"number\": \"212 555-1234\", \"type\": \"home\"},\n    {\"number\": \"646 555-4567\", \"type\": \"office\"}\n  ],\n  \"spouse\": null\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolytypic%2Fpprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolytypic%2Fpprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolytypic%2Fpprint/lists"}