[
  {
    "path": ".credo.exs",
    "content": "%{\n  configs: [\n    %{\n      name: \"default\",\n      files: %{\n        included: [\"lib/\", \"test\"],\n        excluded: []\n      },\n      checks: [\n        {Credo.Check.Consistency.TabsOrSpaces},\n        {Credo.Check.Design.AliasUsage, false},\n        {Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 100}\n      ]\n    }\n  ]\n}\n"
  },
  {
    "path": ".envrc",
    "content": "use nix\n\nexport MIX_HOME=$(pwd)/.mix\nexport PATH=$PATH:$(pwd)/.mix/escripts\n"
  },
  {
    "path": ".github/CODE_OF_CONDUCT.md",
    "content": "# Code of Conduct\n\n## 1. Purpose\n\nA primary goal of Witchcrafters is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof).\n\nThis code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior.\n\nWe invite all those who participate in Witchcrafters to help us create safe and positive experiences for everyone.\n\n## 2. Open Source Citizenship\n\nA supplemental goal of this Code of Conduct is to increase open source citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community.\n\nCommunities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society.\n\nIf you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know.\n\n## 3. Expected Behavior\n\nThe following behaviors are expected and requested of all community members:\n\n*   Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community.\n*   Exercise consideration and respect in your speech and actions.\n*   Attempt collaboration before conflict.\n*   Refrain from demeaning, discriminatory, or harassing behavior and speech.\n*   Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential.\n*   Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations.\n\n## 4. Unacceptable Behavior\n\nThe following behaviors are considered harassment and are unacceptable within our community:\n\n*   Violence, threats of violence or violent language directed against another person.\n*   Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language.\n*   Posting or displaying sexually explicit or violent material.\n*   Posting or threatening to post other people’s personally identifying information (\"doxing\").\n*   Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability.\n*   Inappropriate photography or recording.\n*   Inappropriate physical contact. You should have someone’s consent before touching them.\n*   Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances.\n*   Deliberate intimidation, stalking or following (online or in person).\n*   Advocating for, or encouraging, any of the above behavior.\n*   Sustained disruption of community events, including talks and presentations.\n\n## 5. Consequences of Unacceptable Behavior\n\nUnacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated.\n\nAnyone asked to stop unacceptable behavior is expected to comply immediately.\n\nIf a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event).\n\n## 6. Reporting Guidelines\n\nIf you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. hello@brooklynzelenka.com.\n\n\n\nAdditionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress.\n\n## 7. Addressing Grievances\n\nIf you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify the maintainers with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies.\n\n\n\n## 8. Scope\n\nWe expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues–online and in-person–as well as in all one-on-one communications pertaining to community business.\n\nThis code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members.\n\n## 9. Contact info\n\nhello@fission.codes\n\n## 10. License and attribution\n\nThis Code of Conduct is distributed under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/).\n\nPortions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy).\n\nRetrieved on November 22, 2016 from [http://citizencodeofconduct.org/](http://citizencodeofconduct.org/)\n\n"
  },
  {
    "path": ".github/PULL_REQUEST_TEMPLATE.md",
    "content": "A similar PR may already be submitted!\nPlease search among the [Pull request](../) before creating one.\n\nThanks for submitting a pull request! Please provide enough information so that others can review your pull request:\n\nFor more information, see the `CONTRIBUTING` guide.\n\n\n## Summary\n<!-- Summary of the PR -->\n\nThis PR fixes/implements the following **bugs/features**\n\n* [ ] Bug 1\n* [ ] Bug 2\n* [ ] Feature 1\n* [ ] Feature 2\n* [ ] Breaking changes\n\n<!-- You can skip this if you're fixing a typo or adding an app to the Showcase. -->\n\nExplain the **motivation** for making this change. What existing problem does the pull request solve?\n\n<!-- Example: When \"Adding a function to do X\", explain why it is necessary to have a way to do X. -->\n\n## Test plan (required)\n\nDemonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI.\n\n<!-- Make sure tests pass on Circle CI. -->\n\n\n## Closing issues\n\n<!-- Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such). -->\nFixes #\n\n## After Merge\n* [ ] Does this change invalidate any docs or tutorials? _If so ensure the changes needed are either made or recorded_\n* [ ] Does this change require a release to be made? Is so please create and deploy the release\n"
  },
  {
    "path": ".github/workflows/ci.yaml",
    "content": "on:\n  push:         { \"branches\": [ \"main\" ] }\n  pull_request: { \"branches\": [ \"main\" ] }\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}\n    strategy:\n      matrix:\n        otp: ['23.0']\n        elixir: ['1.11.3']\n    steps:\n      - uses: actions/checkout@v2\n      - uses: erlef/setup-elixir@v1\n        with:\n          otp-version: ${{matrix.otp}}\n          elixir-version: ${{matrix.elixir}}\n      - run: MIX_ENV=test mix deps.get\n      - run: MIX_ENV=test mix test\n      - run: MIX_ENV=test mix credo --strict\n"
  },
  {
    "path": ".github/workflows/greetings.yml",
    "content": "name: Greetings\n\non: [pull_request, issues]\n\njobs:\n  greeting:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/first-interaction@v1\n      with:\n        repo-token: ${{ secrets.GITHUB_TOKEN }}\n        issue-message: 'Thank you for submitting an issue! It means a lot that you took the time -- it helps us be better 🙏'\n        pr-message: \"Thank you for submitting a PR 🎉 It's very appreciated!\"\n"
  },
  {
    "path": ".gitignore",
    "content": "/_build\n/cover\n/deps\n/doc\nerl_crash.dump\n*.ez\n*.beam\n.DS_Store\n.mix\n"
  },
  {
    "path": ".tool-versions",
    "content": "erlang 24.2\nelixir 1.13.2"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2017 Brooklyn Zelenka\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "![](https://github.com/robot-overlord/algae/blob/main/brand/logo.png?raw=true)\n\n[![Build Status](https://travis-ci.org/expede/algae.svg?branch=master)](https://travis-ci.org/expede/algae) [![Inline docs](http://inch-ci.org/github/expede/algae.svg?branch=master)](http://inch-ci.org/github/expede/algae) [![Deps Status](https://beta.hexfaktor.org/badge/all/github/expede/algae.svg)](https://beta.hexfaktor.org/github/expede/algae) [![hex.pm version](https://img.shields.io/hexpm/v/algae.svg?style=flat)](https://hex.pm/packages/algae) [![API Docs](https://img.shields.io/badge/api-docs-yellow.svg?style=flat)](http://hexdocs.pm/algae/) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/expede/algae/blob/master/LICENSE)\n\nAlgae provides a boilerplate-avoiding DSL for defining algebraic data types (ADTs),\nplus several common structures\n\n# Quickstart\nAdd Algae to your list of dependencies in `mix.exs`:\n\n```elixir\n\ndef deps do\n  [{:algae, \"~> 1.2\"}]\nend\n\n```\n\n# Table of Contents\n\n- [Product Builder](#product-builder)\n  - [Definition DSL](#definition-dsl)\n  - [Constructor](#constructor)\n  - [Empty Tag](#empty-tag)\n- [Sum Builder](#sum-builder)\n  - [Default Constructor](#default-constructor)\n  - [Tagged Unions](#tagged-unions)\n- [A Sampling of ADTs](#a-sampling-of-adts)\n  - [`Id`](#algaeid)\n  - [`Maybe`](#algaemaybe)\n  - [`Tree.BinarySearch`](#algaetreebinarysearch)\n\n---\n\n> **NOTE**  \n> Please `import Algae` before trying out the examples below.\n> The samples assume that is has already been done to remove\n> the unnecessary clutter.\n\n---\n\n# Product Builder\nBuild a product type\n\nIncludes:\n\n* Struct\n* Type definition\n* Constructor function (for piping and defaults)\n* Implicit defaults for simple values\n\n## Definition DSL\n\nFor convenience, several variants of the DSL are available.\n\n### Standard\n\n```elixir\ndefmodule Player do\n  # =============== #\n  # Data Definition #\n  # =============== #\n\n  defdata do\n    name       :: String.t()\n    hit_points :: non_neg_integer()\n    experience :: non_neg_integer()\n  end\n\n  # =================== #\n  #    Rest of Module   #\n  # (business as usual) #\n  # =================== #\n\n  @spec attack(t(), t()) :: {t(), t()}\n  def attack(%{experience: xp} = player, %{hit_points: hp} = target) do\n    {\n      %{player | experience: xp + 50},\n      %{target | hit_points: hp - 10}\n    }\n  end\nend\n\n#=> %Player{name: \"Sir Bob\", hit_points: 10, experience: 500}\n```\n\n### Single Field Shorthand\n\nWithout any fields specified, Algae will default to a single field with\nthe same name as the module (essentially a \"wrapper type\"). You must still\nprovide the type for this field, however.\n\nEmbedded in another module:\n\n```elixir\ndefmodule Id do\n  defdata any()\nend\n\n%Id{}\n#=> %Id{id: nil}\n```\n\nStandalone:\n\n```elixir\ndefdata Wrapper :: any()\n\n%Wrapper{}\n#=> %Wrapper{wrapper: nil}\n```\n\n## Constructor\n\nA helper function, especially useful for piping. The order of arguments is\nthe same as the order that they are defined in.\n\n```elixir\ndefmodule Person do\n  defdata do\n    name :: String.t()\n    age  :: non_neg_integer()\n  end\nend\n\nPerson.new(\"Rachel Weintraub\")\n#=> %Person{\n#     name: \"Rachel Weintraub\",\n#     age:  0\n#   }\n```\n\n### Constructor Defaults\n\nFields will automatically default to a sensible value (a typical \"zero\" for\nthat datatype). For example, `non_neg_integer()` will default to `0`,\nand `String.t()` will default to `\"\"`.\n\nYou may also overwrite these defaults with the `\\\\` syntax.\n\n```elixir\ndefmodule Pet do\n  defdata do\n    name      :: String.t()\n    leg_count :: non_neg_integer() \\\\ 4\n  end\nend\n\nPet.new(\"Crookshanks\")\n#=> %Pet{\n#     name: \"Crookshanks\",\n#     leg_count: 4\n#   }\n\nPet.new(\"Paul the Psychic Octopus\", 8)\n#=> %Pet{\n#     name: \"Paul the Psychic Octopus\",\n#     leg_count: 8\n#   }\n```\n\nThis overwriting syntax is _required_ for complex types:\n\n```elixir\ndefdata Grocery do\n  item :: {String.t(), integer(), boolean()} \\\\ {\"Orange\", 4, false}\nend\n\nGrocery.new()\n#=> %Grocery{\n#     item: {\"Orange\", 4, false}\n#   }\n```\n\n### Overwrite Constructor\n\nThe `new` constructor function may be overwritten.\n\n```elixir\ndefmodule Constant do\n  defdata :: fun()\n\n  def new(value), do: %Constant{constant: fn _ -> value end}\nend\n\nfourty_two = Constant.new(42)\nfourty_two.constant.(33)\n#=> 42\n```\n\n## Empty Tag\n\nAn empty type (with no fields) is definable using the `none`() type\n\n```elixir\ndefmodule Nothing do\n  defdata none()\nend\n\nNothing.new()\n#=> %Nothing{}\n```\n\n# Sum Builder\n\nBuild a sum (coproduct) type from product types\n\n```elixir\ndefmodule Light do\n  # ============== #\n  # Sum Definition #\n  # ============== #\n\n  defsum do\n    defdata Red    :: none()\n    defdata Yellow :: none()\n    defdata Green  :: none()\n  end\n\n  # =================== #\n  #    Rest of Module   #\n  # (business as usual) #\n  # =================== #\n\n  def from_number(1), do: %Light.Red{}\n  def from_number(2), do: %Light.Yellow{}\n  def from_number(3), do: %Light.Green{}\nend\n\nLight.new()\n#=> %Light.Red{}\n```\n\n## Embedded Products\n\nData with multiple fields can be defined directly as part of a sum\n\n```elixir\ndefmodule Pet do\n  defsum do\n    defdata Cat do\n      name :: String.t()\n      claw_sharpness :: String.t()\n    end\n\n    defdata Dog do\n      name :: String.t()\n      bark_loudness :: non_neg_integer()\n    end\n  end\nend\n```\n\n## Default Constructor\n\nThe first `defdata`'s constructor will be the default constructor for the sum\n\n```elixir\ndefmodule Maybe do\n  defsum do\n    defdata Nothing :: none()\n    defdata Just    :: any()\n  end\nend\n\nMaybe.new()\n#=> %Maybe.Nothing{}\n```\n\n## Tagged Unions\n\nSums join existing types with tags: new types to help distinguish the context\nthat they are in (the sum type)\n\n```elixir\ndefdata Book  :: String.t() \\\\ \"War and Peace\"\ndefdata Video :: String.t() \\\\ \"2001: A Space Odyssey\"\n\ndefmodule Media do\n  defsum do\n    defdata Paper :: Book.t()\n    defdata Film  :: Video.t() \\\\ Video.new(\"A Clockwork Orange\")\n  end\nend\n\nmedia = Media.new()\n#=> %Paper{\n#      paper: %Book{\n#        book: \"War and Peace\"\n#      }\n#   }\n```\n\n# A Sampling of ADTs\n\nSee [complete docs](https://hexdocs.pm/algae) for more\n\n## `Algae.Id`\n\nThe simplest ADT: a simple wrapper for some data\n\n```elixir\n%Algae.Id{id: \"hi!\"}\n```\n\n## `Algae.Maybe`\n\nMaybe represents the presence or absence of something.\n\nPlease note that `nil` is actually a value, as it can be passed to functions!\n`nil` is not bottom!\n\n```elixir\nAlgae.Maybe.new()\n#=> %Algae.Maybe.Nothing{}\n\nAlgae.Maybe.new(42)\n#=> %Algae.Maybe.Just{just: 42}\n```\n\n## `Tree.BinarySearch`\n\n```elixir\nalias Algae.Tree.BinarySearch, as: BTree\n\n#   42\n#  /  \\\n# 77  1234\n#     /  \\\n#    98  32\n\nBTree.Branch.new(\n  42,\n  BTree.Branch.new(77),\n  BTree.Branch.new(\n    1234,\n    BTree.Branch.new(98),\n    BTree.Branch.new(32)\n  )\n)\n\n#=> %Algae.Tree.BinarySearch.Branch{\n#     value: 42,\n#     left: %Algae.Tree.BinarySearch.Branch{\n#       value: 77,\n#       left:  %Algae.Tree.BinarySearch.Empty{},\n#       right: %Algae.Tree.BinarySearch.Empty{}\n#     },\n#     right: %Algae.Tree.BinarySearch.Branch{\n#       value: 1234,\n#       left:  %Algae.Tree.BinarySearch.Branch{\n#         value: 98,\n#         left:  %Algae.Tree.BinarySearch.Empty{},\n#         right: %Algae.Tree.BinarySearch.Empty{}\n#       },\n#       right: %Algae.Tree.BinarySearch.Branch{\n#         value: 32,\n#         left:  %Algae.Tree.BinarySearch.Empty{},\n#         right: %Algae.Tree.BinarySearch.Empty{}\n#       }\n#     }\n#   }\n```\n"
  },
  {
    "path": "brand/LOGO_LICENSE",
    "content": "ORIGINAL AUTHOR ATTRIBUTION: Gabriele Kothe-Heinrich\nDESCRIPTION: Halidrys siliquosa (L.) Lyngb., herbarium sheet. Collected 1985-09-10, Heligoland (Germany)\nSOURCE: https://commons.wikimedia.org/wiki/File:Halidrys_siliquosa_Helgoland.JPG\nMODIFIED: Yes\n\nLicense\n\nTHE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE (\"CCPL\" OR \"LICENSE\"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.\n\nBY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.\n\n1. Definitions\n\n\"Adaptation\" means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image (\"synching\") will be considered an Adaptation for the purpose of this License.\n\"Collection\" means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(f) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined below) for the purposes of this License.\n\"Creative Commons Compatible License\" means a license that is listed at https://creativecommons.org/compatiblelicenses that has been approved by Creative Commons as being essentially equivalent to this License, including, at a minimum, because that license: (i) contains terms that have the same purpose, meaning and effect as the License Elements of this License; and, (ii) explicitly permits the relicensing of adaptations of works made available under that license under this License or a Creative Commons jurisdiction license with the same License Elements as this License.\n\"Distribute\" means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.\n\"License Elements\" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.\n\"Licensor\" means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.\n\"Original Author\" means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.\n\"Work\" means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.\n\"You\" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.\n\"Publicly Perform\" means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.\n\"Reproduce\" means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.\n2. Fair Dealing Rights. Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.\n\n3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:\n\nto Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;\nto create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked \"The original work was translated from English to Spanish,\" or a modification could indicate \"The original work has been modified.\";\nto Distribute and Publicly Perform the Work including as incorporated in Collections; and,\nto Distribute and Publicly Perform Adaptations.\nFor the avoidance of doubt:\n\nNon-waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;\nWaivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor waives the exclusive right to collect such royalties for any exercise by You of the rights granted under this License; and,\nVoluntary License Schemes. The Licensor waives the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License.\nThe above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved.\n\n4. Restrictions. The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:\n\nYou may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(c), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(c), as requested.\nYou may Distribute or Publicly Perform an Adaptation only under the terms of: (i) this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-ShareAlike 3.0 US)); (iv) a Creative Commons Compatible License. If you license the Adaptation under one of the licenses mentioned in (iv), you must comply with the terms of that license. If you license the Adaptation under the terms of any of the licenses mentioned in (i), (ii) or (iii) (the \"Applicable License\"), you must comply with the terms of the Applicable License generally and the following provisions: (I) You must include a copy of, or the URI for, the Applicable License with every copy of each Adaptation You Distribute or Publicly Perform; (II) You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License; (III) You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform; (IV) when You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License.\nIf You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution (\"Attribution Parties\") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and (iv) , consistent with Ssection 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., \"French translation of the Work by Original Author,\" or \"Screenplay based on original Work by Original Author\"). The credit required by this Section 4(c) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.\nExcept as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.\n5. Representations, Warranties and Disclaimer\n\nUNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.\n\n6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\n\n7. Termination\n\nThis License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.\nSubject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.\n8. Miscellaneous\n\nEach time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.\nEach time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.\nIf any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.\nNo term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.\nThis License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.\nThe rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law."
  },
  {
    "path": "lib/algae/either.ex",
    "content": "defmodule Algae.Either do\n  @moduledoc ~S\"\"\"\n  Represent branching conditions. These could be different return types,\n  error vs nominal value, and so on.\n\n  ## Examples\n\n      iex> require Integer\n      ...>\n      ...> even_odd = fn(value) ->\n      ...>   if Integer.is_even(value) do\n      ...>     Algae.Either.Right.new(value)\n      ...>   else\n      ...>     Algae.Either.Left.new(value)\n      ...>   end\n      ...> end\n      ...>\n      ...> even_odd.(10)\n      %Algae.Either.Right{right: 10}\n      ...> even_odd.(11)\n      %Algae.Either.Left{left: 11}\n  \"\"\"\n\n  import Algae\n\n  defsum do\n    defdata Left  :: any()\n    defdata Right :: any()\n  end\nend\n\nalias Algae.Either.{Left, Right}\nimport TypeClass\nuse Witchcraft\n\n#############\n# Generator #\n#############\n\ndefimpl TypeClass.Property.Generator, for: Algae.Either.Left do\n  def generate(_) do\n    [1, 1.1, \"\", []]\n    |> Enum.random()\n    |> TypeClass.Property.Generator.generate()\n    |> Algae.Either.Left.new()\n  end\nend\n\ndefimpl TypeClass.Property.Generator, for: Algae.Either.Right do\n  def generate(_) do\n    [1, 1.1, \"\", []]\n    |> Enum.random()\n    |> TypeClass.Property.Generator.generate()\n    |> Algae.Either.Right.new()\n  end\nend\n\n##########\n# Setoid #\n##########\n\ndefinst Witchcraft.Setoid, for: Algae.Either.Left do\n  def equivalent?(_, %Right{}), do: false\n  def equivalent?(%Left{left: a}, %Left{left: b}), do: Witchcraft.Setoid.equivalent?(a, b)\nend\n\ndefinst Witchcraft.Setoid, for: Algae.Either.Right do\n  def equivalent?(_, %Left{}), do: false\n  def equivalent?(%Right{right: a}, %Right{right: b}), do: Witchcraft.Setoid.equivalent?(a, b)\nend\n\n#######\n# Ord #\n#######\n\ndefinst Witchcraft.Ord, for: Algae.Either.Left do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Left.new()\n  end\n\n  def compare(_, %Algae.Either.Right{}), do: :lesser\n  def compare(%Left{left: a}, %Left{left: b}), do: Witchcraft.Ord.compare(a, b)\nend\n\ndefinst Witchcraft.Ord, for: Algae.Either.Right do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Right.new()\n  end\n\n  def compare(_, %Left{}), do: :greater\n  def compare(%Right{right: a}, %Right{right: b}), do: Witchcraft.Ord.compare(a, b)\nend\n\n#############\n# Semigroup #\n#############\n\ndefinst Witchcraft.Semigroup, for: Algae.Either.Left do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Left.new()\n  end\n\n  def append(left, %Right{}), do: left\n  def append(%Left{left: a}, %Left{left: b}), do: %Left{left: a <> b}\nend\n\ndefinst Witchcraft.Semigroup, for: Algae.Either.Right do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Algae.Either.Right.new()\n  end\n\n  def append(_, left = %Left{}), do: left\n  def append(%Right{right: a}, %Right{right: b}), do: %Right{right: a <> b}\nend\n\n##########\n# Monoid #\n##########\n\ndefinst Witchcraft.Monoid, for: Algae.Either.Left do\n  def empty(%Left{left: a}), do: %Right{right: Witchcraft.Monoid.empty(a)}\nend\n\ndefinst Witchcraft.Monoid, for: Algae.Either.Right do\n  def empty(%Right{right: a}), do: %Right{right: Witchcraft.Monoid.empty(a)}\nend\n\n# ###########\n# # Functor #\n# ###########\n\ndefinst Witchcraft.Functor, for: Algae.Either.Left do\n  def map(left, _), do: left\nend\n\ndefinst Witchcraft.Functor, for: Algae.Either.Right do\n  def map(%Right{right: data}, fun), do: data |> fun.() |> Right.new()\nend\n\n# ############\n# # Foldable #\n# ############\n\ndefinst Witchcraft.Foldable, for: Algae.Either.Left do\n  def right_fold(_, seed, _), do: seed\nend\n\ndefinst Witchcraft.Foldable, for: Algae.Either.Right do\n  def right_fold(%Right{right: inner}, seed, fun), do: fun.(inner, seed)\nend\n\n# ###############\n# # Traversable #\n# ###############\n\ndefinst Witchcraft.Traversable, for: Algae.Either.Left do\n  @force_type_instance true\n\n  def traverse(left = %Left{left: value}, link) do\n    value\n    |> link.()\n    |> of(left)\n  end\nend\n\ndefinst Witchcraft.Traversable, for: Algae.Either.Right do\n  def traverse(%Right{right: value}, link), do: map(link.(value), &Right.new/1)\nend\n\n# #########\n# # Apply #\n# #########\n\ndefinst Witchcraft.Apply, for: Algae.Either.Left do\n  def convey(left, _), do: left\nend\n\ndefinst Witchcraft.Apply, for: Algae.Either.Right do\n  def convey(_,   left = %Left{}), do: left\n  def convey(data, %Right{right: fun}), do: map(data, fun)\nend\n\n###############\n# Applicative #\n###############\n\ndefinst Witchcraft.Applicative, for: Algae.Either.Left do\n  @force_type_instance true\n\n  def of(_, data), do: Right.new(data)\nend\n\ndefinst Witchcraft.Applicative, for: Algae.Either.Right do\n  def of(_, data), do: Right.new(data)\nend\n\n# #########\n# # Chain #\n# #########\n\ndefinst Witchcraft.Chain, for: Algae.Either.Left do\n  def chain(left, _), do: left\nend\n\ndefinst Witchcraft.Chain, for: Algae.Either.Right do\n  def chain(%Right{right: data}, link), do: link.(data)\nend\n\n# #########\n# # Monad #\n# #########\n\ndefinst Witchcraft.Monad, for: Algae.Either.Left\ndefinst Witchcraft.Monad, for: Algae.Either.Right\n\n# ##########\n# # Extend #\n# ##########\n\ndefinst Witchcraft.Extend, for: Algae.Either.Left do\n  def nest(_), do: Left.new()\nend\n\ndefinst Witchcraft.Extend, for: Algae.Either.Right do\n  def nest(inner), do: Right.new(inner)\nend\n"
  },
  {
    "path": "lib/algae/free.ex",
    "content": "defmodule Algae.Free do\n  @moduledoc \"\"\"\n  A \"free\" structure that converts functors into monads by embedding them in\n  a special structure with all of the monadic heavy lifting done for you.\n\n  Similar to trees and lists, but with the ability to add a struct \"tag\",\n  at each level. Often used for DSLs, interpreters, or building structured data.\n\n  For a simple introduction to the \"free monad + interpreter\" pattern, we recommend\n  [Why free monads matter](http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html).\n\n  ## Anatomy\n\n  ### Pure\n\n  `Pure` simply holds a plain value.\n\n      %Free.Pure{pure: 42}\n\n  ### Roll\n\n  `Roll` resursively containment of more `Free` structures embedded in\n  a another ADT. For example, with `Id`:\n\n      %Free.Roll{\n        roll: %Id{\n          id: %Pure{\n            pure: 42\n          }\n        }\n      }\n\n  \"\"\"\n\n  alias __MODULE__\n  alias Algae.Free.{Pure, Roll}\n\n  import Algae\n\n  use Witchcraft\n\n  defsum do\n    defdata(Roll :: any())\n    defdata(Pure :: any() \\\\ %Witchcraft.Unit{})\n  end\n\n  @doc \"\"\"\n  Create an `Algae.Free.Pure` wrapping a single, simple value\n\n  ## Examples\n\n      iex> new(42)\n      %Algae.Free.Pure{pure: 42}\n\n  \"\"\"\n  @spec new(any()) :: t()\n  def new(value), do: %Pure{pure: value}\n\n  @doc \"\"\"\n  Add another layer to a free structure\n\n  ## Examples\n\n      iex> 13\n      ...> |> new()\n      ...> |> layer(%Algae.Id{})\n      %Algae.Free.Roll{\n        roll: %Algae.Id{\n          id: %Algae.Free.Pure{\n            pure: 13\n          }\n        }\n      }\n\n  \"\"\"\n  @spec layer(t(), any()) :: t()\n  def layer(free, mutual), do: %Roll{roll: of(mutual, free)}\n\n  @doc \"\"\"\n  Wrap a functor in a free structure.\n\n  ## Examples\n\n      iex> wrap(%Algae.Id{id: 42})\n      %Algae.Free.Roll{\n        roll: %Algae.Id{\n          id: 42\n        }\n      }\n\n  \"\"\"\n  @spec wrap(Witchcraft.Functor.t()) :: Roll.t()\n  def wrap(functor), do: %Roll{roll: functor}\n\n  @doc \"\"\"\n  Lift a plain functor up into a free monad.\n\n  ## Examples\n\n      iex> free(%Algae.Id{id: 42})\n      %Algae.Free.Roll{\n        roll: %Algae.Id{\n          id: %Algae.Free.Pure{\n            pure: 42\n          }\n        }\n      }\n\n  \"\"\"\n  @spec free(Witchcraft.Functor.t()) :: t()\n  def free(functor) do\n    functor\n    |> map(&of(%Roll{}, &1))\n    |> wrap()\n  end\nend\n\nalias Algae.Free\nalias Algae.Free.{Pure, Roll}\nalias TypeClass.Property.Generator\nalias Witchcraft.{Apply, Chain, Functor, Ord, Setoid}\nimport TypeClass\nuse Witchcraft\n\n#############\n# Generator #\n#############\n\ndefimpl TypeClass.Property.Generator, for: Algae.Free.Pure do\n  def generate(_) do\n    [1, 1.1, \"\", []]\n    |> Enum.random()\n    |> Generator.generate()\n    |> Pure.new()\n  end\nend\n\ndefimpl TypeClass.Property.Generator, for: Algae.Free.Roll do\n  def generate(_) do\n    inner = Algae.Id.new()\n\n    seed =\n      [1, 1.1, \"\", []]\n      |> Enum.random()\n      |> Generator.generate()\n\n    seed\n    |> Free.new()\n    |> Free.layer(inner)\n    |> Free.layer(inner)\n  end\nend\n\n##########\n# Setoid #\n##########\n\ndefinst Witchcraft.Setoid, for: Algae.Free.Pure do\n  custom_generator(_) do\n    1\n    |> Generator.generate()\n    |> Pure.new()\n  end\n\n  def equivalent?(_, %Roll{}), do: false\n  def equivalent?(%Pure{pure: a}, %Pure{pure: b}), do: Setoid.equivalent?(a, b)\nend\n\ndefinst Witchcraft.Setoid, for: Algae.Free.Roll do\n  custom_generator(_) do\n    inner = Algae.Id.new()\n    seed = Generator.generate(1)\n\n    seed\n    |> Free.new()\n    |> Free.layer(inner)\n    |> Free.layer(inner)\n  end\n\n  def equivalent?(_, %Pure{}), do: false\n  def equivalent?(%Roll{roll: a}, %Roll{roll: b}), do: Setoid.equivalent?(a, b)\nend\n\n#######\n# Ord #\n#######\n\ndefinst Witchcraft.Ord, for: Algae.Free.Pure do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Free.new()\n  end\n\n  def compare(_, %Roll{}), do: :lesser\n  def compare(%Pure{pure: a}, %Pure{pure: b}), do: Ord.compare(a, b)\nend\n\ndefinst Witchcraft.Ord, for: Algae.Free.Roll do\n  custom_generator(_) do\n    inner = Algae.Id.new()\n    seed = Generator.generate(1)\n\n    seed\n    |> Free.new()\n    |> Free.layer(inner)\n    |> Free.layer(inner)\n  end\n\n  def compare(%Roll{}, %Pure{}), do: :greater\n  def compare(%Roll{roll: a}, %Roll{roll: b}), do: Ord.compare(a, b)\nend\n\n###########\n# Functor #\n###########\n\ndefinst Witchcraft.Functor, for: Algae.Free.Pure do\n  def map(%Pure{pure: data}, fun), do: %Pure{pure: fun.(data)}\nend\n\ndefinst Witchcraft.Functor, for: Algae.Free.Roll do\n  def map(%Roll{roll: data}, fun) do\n    data\n    |> Functor.map(&Functor.map(&1, fun))\n    |> Roll.new()\n  end\nend\n\n#########\n# Apply #\n#########\n\ndefinst Witchcraft.Apply, for: Algae.Free.Pure do\n  def convey(%Pure{pure: data}, %Pure{pure: fun}), do: %Pure{pure: fun.(data)}\n\n  def convey(pure, %Roll{roll: rolled}) do\n    rolled\n    |> Functor.map(&Apply.convey(pure, &1))\n    |> Roll.new()\n  end\nend\n\ndefinst Witchcraft.Apply, for: Algae.Free.Roll do\n  def convey(%Roll{roll: rolled}, %Pure{pure: fun}) do\n    rolled\n    |> Functor.map(&Functor.map(&1, fun))\n    |> Roll.new()\n  end\n\n  def convey(roll, %Roll{roll: rolled}) do\n    rolled\n    |> Functor.map(&Apply.convey(roll, &1))\n    |> Roll.new()\n  end\nend\n\n###############\n# Applicative #\n###############\n\ndefinst Witchcraft.Applicative, for: Algae.Free.Pure do\n  def of(_, value), do: %Pure{pure: value}\nend\n\ndefinst Witchcraft.Applicative, for: Algae.Free.Roll do\n  def of(_, value), do: %Pure{pure: value}\nend\n\n#########\n# Chain #\n#########\n\ndefinst Witchcraft.Chain, for: Algae.Free.Pure do\n  def chain(%Pure{pure: pure}, link), do: link.(pure)\nend\n\ndefinst Witchcraft.Chain, for: Algae.Free.Roll do\n  def chain(%Roll{roll: rolled}, link) do\n    rolled\n    |> Functor.map(&Chain.chain(&1, link))\n    |> Roll.new()\n  end\nend\n\n#########\n# Monad #\n#########\n\ndefinst(Witchcraft.Monad, for: Algae.Free.Pure)\ndefinst(Witchcraft.Monad, for: Algae.Free.Roll)\n"
  },
  {
    "path": "lib/algae/id/applicative.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Applicative, for: Algae.Id do\n  def of(_, data), do: Algae.Id.new(data)\nend\n"
  },
  {
    "path": "lib/algae/id/apply.ex",
    "content": "import TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Apply, for: Algae.Id do\n  def convey(data, %{id: fun}), do: map(data, fun)\nend\n"
  },
  {
    "path": "lib/algae/id/chain.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Chain, for: Algae.Id do\n  def chain(%{id: data}, link), do: link.(data)\nend\n"
  },
  {
    "path": "lib/algae/id/comonad.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Comonad, for: Algae.Id do\n  def extract(%{id: inner}), do: inner\nend\n"
  },
  {
    "path": "lib/algae/id/extend.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Extend, for: Algae.Id do\n  def nest(inner), do: Algae.Id.new(inner)\nend\n"
  },
  {
    "path": "lib/algae/id/foldable.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Foldable, for: Algae.Id do\n  def right_fold(%{id: data}, seed, fun), do: fun.(data, seed)\nend\n"
  },
  {
    "path": "lib/algae/id/functor.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Functor, for: Algae.Id do\n  def map(%{id: data}, fun), do: data |> fun.() |> Algae.Id.new()\nend\n"
  },
  {
    "path": "lib/algae/id/generator.ex",
    "content": "defimpl TypeClass.Property.Generator, for: Algae.Id do\n  def generate(_) do\n    [1, 1.1, \"\", []]\n    |> Enum.random()\n    |> TypeClass.Property.Generator.generate()\n    |> Algae.Id.new()\n  end\nend\n"
  },
  {
    "path": "lib/algae/id/monad.ex",
    "content": "import TypeClass\ndefinst Witchcraft.Monad, for: Algae.Id\n"
  },
  {
    "path": "lib/algae/id/monoid.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Monoid, for: Algae.Id do\n  def empty(%{id: sample}), do: sample |> Witchcraft.Monoid.empty() |> Algae.Id.new()\nend\n"
  },
  {
    "path": "lib/algae/id/ord.ex",
    "content": "import TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Ord, for: Algae.Id do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Algae.Id.new()\n  end\n\n  def compare(%{id: a}, %{id: b}), do: Witchcraft.Ord.compare(a, b)\nend\n"
  },
  {
    "path": "lib/algae/id/semigroup.ex",
    "content": "import TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Semigroup, for: Algae.Id do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Algae.Id.new()\n  end\n\n  def append(%{id: a}, %{id: b}), do: %Algae.Id{id: a <> b}\nend\n"
  },
  {
    "path": "lib/algae/id/setoid.ex",
    "content": "import TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Setoid, for: Algae.Id do\n  def equivalent?(%{id: a}, %{id: b}), do: a == b\nend\n"
  },
  {
    "path": "lib/algae/id/traversable.ex",
    "content": "import TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Traversable, for: Algae.Id do\n  def traverse(%{id: data}, link) do\n    data\n    |> link.()\n    |> map(&Algae.Id.new/1)\n  end\nend\n"
  },
  {
    "path": "lib/algae/id.ex",
    "content": "defmodule Algae.Id do\n  @moduledoc ~S\"\"\"\n  The simplest ADT: a simple wrapper for some data\n\n  ## Examples\n\n      iex> %Algae.Id{id: \"hi!\"}\n      %Algae.Id{id: \"hi!\"}\n\n  \"\"\"\n\n  import Algae\n\n  defdata any()\n\n  @doc \"\"\"\n  Wrap some data in an `Algae.Id` wrapper\n\n  ## Examples\n\n      iex> new(42)\n      %Algae.Id{id: 42}\n\n  \"\"\"\n  @spec new(any()) :: t()\n  def new(inner), do: %Algae.Id{id: inner}\nend\n"
  },
  {
    "path": "lib/algae/internal/needs_explicit_default_error.ex",
    "content": "defmodule Algae.Internal.NeedsExplicitDefaultError do\n  defexception message: \"Needs explicit default value\"\nend\n"
  },
  {
    "path": "lib/algae/internal.ex",
    "content": "defmodule Algae.Internal do\n  @moduledoc false\n\n  @type ast() :: {atom(), any(), any()}\n\n  @doc \"\"\"\n  Construct a data type AST\n  \"\"\"\n  @spec data_ast(module(), Macro.Env.t() | [module()], ast()) :: ast()\n  def data_ast(lines, %{aliases: _} = caller) when is_list(lines) do\n    {field_values, field_types, specs, args, defaults} = module_elements(lines, caller)\n\n    arg_count = Enum.count(args)\n\n    overridables =\n      Enum.map(0..arg_count, &({:new_partial, &1}))\n      ++ [new: arg_count]\n    # More verbose, but clearer.\n    # for arity <- 0..Enum.count(args) do\n    #   {:new, arity}\n    # end\n\n    args_without_defaults =\n      Enum.map(args, fn({:\\\\, [], [stripped, _]}) -> stripped end)\n\n    quote do\n      use Quark\n\n      @type t :: %__MODULE__{unquote_splicing(field_types)}\n      defstruct unquote(field_values)\n\n      defpartial new_partial(unquote_splicing(args_without_defaults)) do\n        struct(__MODULE__, unquote(defaults))\n      end\n\n      @doc \"Positional constructor, with args in the same order as they were defined in\"\n      @spec new(unquote_splicing(specs)) :: t()\n      def new(unquote_splicing(args)) do\n        struct(__MODULE__, unquote(defaults))\n      end\n\n      defoverridable unquote(overridables)\n    end\n  end\n\n  def data_ast(modules, {:none, _, _}) do\n    full_module = modules |> List.wrap() |> Module.concat()\n\n    quote do\n      defmodule unquote(full_module) do\n        @type t :: %__MODULE__{}\n\n        defstruct []\n\n        @doc \"Default #{__MODULE__} struct\"\n        @spec new() :: t()\n        def new, do: struct(__MODULE__)\n\n        defoverridable [new: 0]\n      end\n    end\n  end\n\n  def data_ast(caller_module, type) do\n    default = default_value(type)\n    field = module_to_field(caller_module)\n\n    quote do\n      @type t :: %unquote(caller_module){\n        unquote(field) => unquote(type)\n      }\n\n      defstruct [{unquote(field), unquote(default)}]\n\n      @doc \"Default #{__MODULE__} struct\"\n      @spec new() :: t()\n      def new, do: struct(__MODULE__)\n\n      @doc \"Constructor helper for piping\"\n      @spec new(unquote(type)) :: t()\n      def new(field), do: struct(__MODULE__, [unquote(field), field])\n\n      defoverridable [new: 0, new: 1]\n    end\n  end\n\n  @spec data_ast([module()], any(), ast()) :: ast()\n  def data_ast(name, default, type_ctx) do\n    full_module = Module.concat(name)\n    field = module_to_field(name)\n\n    quote do\n      defmodule unquote(full_module) do\n        @type t :: %unquote(full_module){\n          unquote(field) => unquote(type_ctx)\n        }\n\n        defstruct [{unquote(field), unquote(default)}]\n\n        @doc \"Default #{__MODULE__} struct. Value defaults to #{inspect unquote(default)}.\"\n        @spec new() :: t()\n        def new, do: struct(__MODULE__)\n\n        @doc \"Helper for initializing struct with a specific value\"\n        @spec new(unquote(type_ctx)) :: t()\n        def new(value), do: struct(__MODULE__, [{unquote(field), value}])\n      end\n    end\n  end\n\n  @spec embedded_data_ast() :: ast()\n  def embedded_data_ast do\n    quote do\n      @type t :: %__MODULE__{}\n      defstruct []\n\n      @doc \"Default #{__MODULE__} struct\"\n      @spec new() :: t()\n      def new, do: struct(__MODULE__)\n    end\n  end\n\n  def embedded_data_ast(module_ctx, default, type_ctx) do\n    field = module_to_field(module_ctx)\n    quote do\n      @type t :: %__MODULE__{\n        unquote(field) => unquote(type_ctx)\n      }\n\n      defstruct [{unquote(field), unquote(default)}]\n\n      @doc \"Default #{__MODULE__} struct\"\n      @spec new(unquote(type_ctx)) :: t()\n      def new(field \\\\ unquote(default)), do: struct(__MODULE__, [field])\n\n      defoverridable [new: 1]\n    end\n  end\n\n  @type field :: {atom(), [any()], [any()]}\n  @type type  :: {atom(), [any()], [any()]}\n\n  @spec module_elements([ast()], Macro.Env.t())\n     :: {\n          [{field(), any()}],\n          [{field(), type()}],\n          [type],\n          [{:\\\\, [], any()}],\n          [{field(), any()}]\n        }\n  def module_elements(lines, caller) do\n    List.foldr(lines, {[], [], [], [], []},\n      fn(line, {value_acc, type_acc, typespec_acc, acc_arg, acc_mapping}) ->\n        {field, type, default_value} = normalize_elements(line, caller)\n        arg = {field, [], Elixir}\n\n        {\n          [{field, default_value} | value_acc],\n          [{field, type} | type_acc],\n          [type | typespec_acc],\n          [{:\\\\, [], [arg, default_value]} | acc_arg],\n          [{field, arg} | acc_mapping]\n        }\n      end)\n  end\n\n  @spec normalize_elements(ast(), Macro.Env.t()) :: {atom(), type(), any()}\n  def normalize_elements({:::, _, [{field, _, _}, type]}, caller) do\n    expanded_type = resolve_alias(type, caller)\n    {field, expanded_type, default_value(expanded_type)}\n  end\n\n  def normalize_elements({:\\\\, _, [{:::, _, [{field, _, _}, type]}, default]}, _) do\n    {field, type, default}\n  end\n\n  @spec resolve_alias(ast(), Macro.Env.t()) :: ast()\n  def resolve_alias({{_, _, _} = a, b, c}, caller) do\n    {resolve_alias(a, caller), b, c}\n  end\n\n  def resolve_alias({:. = a, b, [{:__aliases__, _, _} = the_alias | rest]}, caller) do\n    resolved_alias = Macro.expand(the_alias, caller)\n    {a, b, [resolved_alias | rest]}\n  end\n\n  def resolve_alias(a, _), do: a\n\n  @spec or_types([ast()], module()) :: [ast()]\n  def or_types({:\\\\, _, [{:::, _, [_, types]}, _]}, module_ctx) do\n    or_types(types, module_ctx)\n  end\n\n  def or_types([head | tail], module_ctx) do\n    Enum.reduce(tail, call_type(head, module_ctx), fn(module, acc) ->\n      {:|, [], [call_type(module, module_ctx), acc]}\n    end)\n  end\n\n  @spec modules(module(), [module()]) :: [module()]\n  def modules(top, module_ctx), do: [top | extract_name(module_ctx)]\n\n  @spec call_type(module(), [module()]) :: ast()\n  def call_type(new_module, module_ctx) do\n    full_module = List.wrap(module_ctx) ++ submodule_name(new_module)\n    {{:., [], [{:__aliases__, [alias: false], full_module}, :t]}, [], []}\n  end\n\n  @spec submodule_name({:defdata, any(), [{:::, any(), [any()]}]})\n     :: [module()]\n  def submodule_name({:defdata, _, [{:::, _, [body, _]}]}) do\n    body\n    |> case do\n      {:\\\\, _, [inner_module_ctx, _]} -> inner_module_ctx\n      {:__aliases__, _, module} -> module\n      outer_module_ctx -> outer_module_ctx\n    end\n    |> List.wrap()\n  end\n\n  def submodule_name({:defdata, _, [{:\\\\, _, [{:::, _, [{:__aliases__, _, module}, _]}, _]}]}) do\n    List.wrap(module)\n  end\n\n  def submodule_name({:defdata, _, [{:__aliases__, _, module}, _]}) do\n    List.wrap(module)\n  end\n\n  @spec extract_name({any(), any(), atom()} | [module()]) :: [module()]\n  def extract_name({_, _, inner_name}), do: List.wrap(inner_name)\n  def extract_name(module_chain) when is_list(module_chain), do: module_chain\n\n  def module_to_field(modules) when is_list(modules) do\n    modules\n    |> List.last()\n    |> module_to_field()\n  end\n\n  def module_to_field(module) do\n    module\n    |> Atom.to_string()\n    |> String.split(\".\")\n    |> List.last()\n    |> String.downcase()\n    |> String.trim_leading(\"elixir.\")\n    |> String.to_atom()\n  end\n\n  # credo:disable-for-lines:21 Credo.Check.Refactor.CyclomaticComplexity\n  def default_value({{:., _, [{_, _, [:String]}, :t]}, _, _}), do: \"\"\n  def default_value({{:., _, [String, :t]}, _, _}), do: \"\"\n\n  def default_value({{:., _, [{_, _, adt}, :t]}, _, []}) do\n    quote do: unquote(Module.concat(adt)).new()\n  end\n\n  def default_value({{:., _, [module, :t]}, _, []}) do\n    quote do: unquote(module).new()\n  end\n\n  def default_value([_]), do: []\n\n  def default_value({type, _, _}) do\n    type\n    |> case do\n      :boolean -> false\n\n      :number  -> 0\n      :integer -> 0\n\n      :float -> 0.0\n\n      :pos_integer     -> 1\n      :non_neg_integer -> 0\n\n      :bitstring -> \"\"\n      :charlist  -> []\n\n      []    -> []\n      :list -> []\n\n      :map  -> %{}\n\n      :fun -> &Quark.id/1\n      :->  -> &Quark.id/1\n\n      :any -> nil\n      :t   -> raise %Algae.Internal.NeedsExplicitDefaultError{message: \"Type is lone `t`\"}\n\n      atom -> atom\n    end\n    |> Macro.escape()\n  end\nend\n"
  },
  {
    "path": "lib/algae/maybe.ex",
    "content": "defmodule Algae.Maybe do\n  @moduledoc ~S\"\"\"\n  The sum of `Algae.Maybe.Just` and `Algae.Maybe.Nothing`.\n  Maybe represents the presence or absence of something.\n\n  Please note that `nil` is actually a value, as it can be passed to functions!\n  `nil` is not bottom!\n\n  ## Examples\n\n      iex> [1,2,3]\n      ...> |> List.first()\n      ...> |> case do\n      ...>      nil  -> new()\n      ...>      head -> new(head)\n      ...>    end\n      %Algae.Maybe.Just{just: 1}\n\n      iex> []\n      ...> |> List.first()\n      ...> |> case do\n      ...>      nil  -> new()\n      ...>      head -> new(head)\n      ...>    end\n      %Algae.Maybe.Nothing{}\n\n  \"\"\"\n\n  import Algae\n  alias Algae.Maybe.{Just, Nothing}\n\n  defsum do\n    defdata Nothing :: none()\n    defdata Just    :: any()\n  end\n\n  @doc ~S\"\"\"\n  Put no value into the `Maybe` context (ie: make it a `Nothing`)\n\n  ## Examples\n\n      iex> new()\n      %Algae.Maybe.Nothing{}\n\n  \"\"\"\n  @spec new() :: Nothing.t()\n  defdelegate new, to: Nothing, as: :new\n\n  @doc ~S\"\"\"\n  Put a value into the `Maybe` context (ie: make it a `Just`)\n\n  ## Examples\n\n      iex> new(9)\n      %Algae.Maybe.Just{just: 9}\n\n      iex> new(nil)\n      %Algae.Maybe.Just{just: nil}\n\n      iex> new(nil, nothing: nil)\n      %Algae.Maybe.Nothing{}\n\n      iex> new(9, nothing: 9)\n      %Algae.Maybe.Nothing{}\n\n      iex> new(9, nothing: 1)\n      %Algae.Maybe.Just{just: 9}\n\n  \"\"\"\n  @spec new(any(), [nothing: any()]) :: Just.t() | Nothing.t()\n  def new(nothing_value, [nothing: nothing_value]), do: Nothing.new()\n  def new(value, _), do: Just.new(value)\n\n  @spec new(any()) :: Just.t()\n  def new(value), do: Just.new(value)\n\n  @doc \"\"\"\n  Alias for `new(value, nothing: nil)`.\n\n  ## Examples\n\n      iex> from_nillable(9)\n      %Algae.Maybe.Just{just: 9}\n\n      iex> from_nillable(nil)\n      %Algae.Maybe.Nothing{}\n\n  \"\"\"\n  @spec from_nillable(any()) :: Just.t()\n  def from_nillable(value), do: new(value, nothing: nil)\n\n  @doc \"\"\"\n  Extract a value from a `Maybe`, falling back to a set value in the `Nothing` case.\n\n  ## Examples\n\n      iex> from_maybe(%Algae.Maybe.Nothing{}, else: 42)\n      42\n\n      iex> %Algae.Maybe.Just{just: 1955} |> from_maybe(else: 42)\n      1955\n\n  \"\"\"\n  @spec from_maybe(t(), any()) :: any()\n  def from_maybe(%Nothing{}, [else: fallback]), do: fallback\n  def from_maybe(%Just{just: inner}, _), do: inner\nend\n\nalias Algae.Maybe.{Just, Nothing}\nimport TypeClass\nuse Witchcraft\n\n#############\n# Generator #\n#############\n\ndefimpl TypeClass.Property.Generator, for: Algae.Maybe.Nothing do\n  def generate(_), do: Nothing.new()\nend\n\ndefimpl TypeClass.Property.Generator, for: Algae.Maybe.Just do\n  def generate(_) do\n    [1, 1.1, \"\", []]\n    |> Enum.random()\n    |> TypeClass.Property.Generator.generate()\n    |> Just.new()\n  end\nend\n\n##########\n# Setoid #\n##########\n\ndefinst Witchcraft.Setoid, for: Algae.Maybe.Nothing do\n  def equivalent?(_, %Nothing{}), do: true\n  def equivalent?(_, %Just{}),    do: false\nend\n\ndefinst Witchcraft.Setoid, for: Algae.Maybe.Just do\n  def equivalent?(%Just{just: a}, %Just{just: b}), do: Witchcraft.Setoid.equivalent?(a, b)\n  def equivalent?(%Just{}, %Nothing{}), do: false\nend\n\n#######\n# Ord #\n#######\n\ndefinst Witchcraft.Ord, for: Algae.Maybe.Nothing do\n  def compare(_, %Nothing{}), do: :equal\n  def compare(_, %Just{}),    do: :lesser\nend\n\ndefinst Witchcraft.Ord, for: Algae.Maybe.Just do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Just.new()\n  end\n\n  def compare(%Just{just: a}, %Just{just: b}), do: Witchcraft.Ord.compare(a, b)\n  def compare(%Just{}, %Nothing{}), do: :greater\nend\n\n#############\n# Semigroup #\n#############\n\ndefinst Witchcraft.Semigroup, for: Algae.Maybe.Nothing do\n  def append(_, right), do: right\nend\n\ndefinst Witchcraft.Semigroup, for: Algae.Maybe.Just do\n  custom_generator(_) do\n    1\n    |> TypeClass.Property.Generator.generate()\n    |> Just.new()\n  end\n\n  def append(%Just{just: a}, %Just{just: b}), do: %Just{just: a <> b}\n  def append(just, %Nothing{}), do: just\nend\n\n##########\n# Monoid #\n##########\n\ndefinst Witchcraft.Monoid, for: Algae.Maybe.Nothing do\n  def empty(nothing), do: nothing\nend\n\ndefinst Witchcraft.Monoid, for: Algae.Maybe.Just do\n  def empty(_), do: %Algae.Maybe.Nothing{}\nend\n\n###########\n# Functor #\n###########\n\ndefinst Witchcraft.Functor, for: Algae.Maybe.Nothing do\n  def map(_, _), do: %Algae.Maybe.Nothing{}\nend\n\ndefinst Witchcraft.Functor, for: Algae.Maybe.Just do\n  def map(%{just: data}, fun), do: data |> fun.() |> Algae.Maybe.Just.new()\nend\n\n############\n# Foldable #\n############\n\ndefinst Witchcraft.Foldable, for: Algae.Maybe.Nothing do\n  def right_fold(_, seed, _), do: seed\nend\n\ndefinst Witchcraft.Foldable, for: Algae.Maybe.Just do\n  def right_fold(%Just{just: inner}, seed, fun), do: fun.(inner, seed)\nend\n\n###############\n# Traversable #\n###############\n\n# Not traversable because we don't have enough type information for Nothing\n\n#########\n# Apply #\n#########\n\ndefinst Witchcraft.Apply, for: Algae.Maybe.Nothing do\n  def convey(_, _), do: %Algae.Maybe.Nothing{}\nend\n\ndefinst Witchcraft.Apply, for: Algae.Maybe.Just do\n  alias Algae.Maybe.{Just, Nothing}\n\n  def convey(data, %Nothing{}), do: %Nothing{}\n  def convey(data, %Just{just: fun}), do: map(data, fun)\nend\n\n###############\n# Applicative #\n###############\n\ndefinst Witchcraft.Applicative, for: Algae.Maybe.Nothing do\n  def of(_, data), do: Just.new(data)\nend\n\ndefinst Witchcraft.Applicative, for: Algae.Maybe.Just do\n  def of(_, data), do: Just.new(data)\nend\n\n#########\n# Chain #\n#########\n\ndefinst Witchcraft.Chain, for: Algae.Maybe.Nothing do\n  def chain(_, _), do: %Nothing{}\nend\n\ndefinst Witchcraft.Chain, for: Algae.Maybe.Just do\n  def chain(%{just: data}, link), do: link.(data)\nend\n\n#########\n# Monad #\n#########\n\ndefinst Witchcraft.Monad, for: Algae.Maybe.Nothing\ndefinst Witchcraft.Monad, for: Algae.Maybe.Just\n\n##########\n# Extend #\n##########\n\ndefinst Witchcraft.Extend, for: Algae.Maybe.Nothing do\n  def nest(_), do: %Nothing{}\nend\n\ndefinst Witchcraft.Extend, for: Algae.Maybe.Just do\n  def nest(inner), do: Just.new(inner)\nend\n"
  },
  {
    "path": "lib/algae/reader/applicative.ex",
    "content": "alias  Algae.Reader\nimport TypeClass\nuse    Witchcraft\n\ndefinst Witchcraft.Applicative, for: Algae.Reader do\n  @force_type_instance true\n  def of(_, value), do: Reader.new(fn _ -> value end)\nend\n"
  },
  {
    "path": "lib/algae/reader/apply.ex",
    "content": "alias  Algae.Reader\nimport TypeClass\n\nuse Quark\nuse Witchcraft\n\ndefinst Witchcraft.Apply, for: Algae.Reader do\n  @force_type_instance true\n  def convey(%Reader{reader: fun_a}, %Reader{reader: fun_b}) do\n    Reader.new(fn e -> curry(fun_a).(e).(fun_b.(e)) end)\n  end\nend\n"
  },
  {
    "path": "lib/algae/reader/chain.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Chain, for: Algae.Reader do\n  @force_type_instance true\n  alias  Algae.Reader\n\n  def chain(reader, link) do\n    Reader.new(fn e ->\n      reader\n      |> Reader.run(e)\n      |> link.()\n      |> Reader.run(e)\n    end)\n  end\nend\n"
  },
  {
    "path": "lib/algae/reader/functor.ex",
    "content": "alias  Algae.Reader\nimport TypeClass\nuse    Witchcraft\n\ndefinst Witchcraft.Functor, for: Algae.Reader do\n  @force_type_instance true\n  def map(%Reader{reader: inner}, fun), do: Reader.new(fn e -> e |> inner.() |> fun.() end)\nend\n"
  },
  {
    "path": "lib/algae/reader/generator.ex",
    "content": "defimpl TypeClass.Property.Generator, for: Algae.Reader do\n  def generate(_) do\n    fn -> nil end\n    |> TypeClass.Property.Generator.generate()\n    |> Algae.Reader.new()\n  end\nend\n"
  },
  {
    "path": "lib/algae/reader/monad.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Monad, for: Algae.Reader do\n  @force_type_instance true\nend\n"
  },
  {
    "path": "lib/algae/reader.ex",
    "content": "defmodule Algae.Reader do\n  @moduledoc ~S\"\"\"\n  `Algae.Reader` allows you to pass some readable context around through actions.\n\n  This is useful in a number of situations, but the most common case is to weave\n  access to environment variables monadically.\n\n  For an illustrated guide to `Reader`s,\n  see [Thee Useful Monads](http://adit.io/posts/2013-06-10-three-useful-monads.html#the-state-monad).\n\n  ## Examples\n\n      iex> use Witchcraft\n      ...>\n      iex> correct =\n      ...>   monad %Algae.Reader{} do\n      ...>     count    <- ask &Map.get(&1, :count)\n      ...>     bindings <- ask()\n      ...>     return (count == map_size(bindings))\n      ...>   end\n      ...>\n      iex> sample_bindings = %{count: 3, a: 1, b: 2}\n      iex> correct_count   = run(correct, sample_bindings)\n      iex> \"Correct count for #{inspect sample_bindings}? #{correct_count}\"\n      \"Correct count for %{a: 1, b: 2, count: 3}? true\"\n      ...>\n      iex> bad_bindings = %{count: 100, a: 1, b: 2}\n      iex> bad_count    = run(correct, bad_bindings)\n      iex> \"Correct count for #{inspect bad_bindings}? #{bad_count}\"\n      \"Correct count for %{a: 1, b: 2, count: 100}? false\"\n\n  Example adapted from\n  [source](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Reader.html)\n\n  \"\"\"\n\n  alias  __MODULE__\n  import Algae\n  use    Witchcraft\n\n  defdata fun()\n\n  @doc \"\"\"\n  `Reader` constructor.\n\n  ## Examples\n\n      iex> newbie = new(fn x -> x * 10 end)\n      ...> newbie.reader.(10)\n      100\n\n  \"\"\"\n  @spec new(fun()) :: t()\n  def new(fun), do: %Reader{reader: fun}\n\n  @doc \"\"\"\n  Run the reader function with some argument.\n\n      iex> reader = new(fn x -> x + 5 end)\n      ...> run(reader, 42)\n      47\n\n  This is the opposite of `new/1`.\n\n      iex> fun = fn x -> x + 5 end\n      ...> fun.(42) == fun |> new() |> run(42)\n      true\n\n  \"\"\"\n  @spec run(t(), any()) :: any()\n  def run(%Reader{reader: fun}, arg), do: fun.(arg)\n\n  @doc \"\"\"\n  Get the wrapped environment. Especially useful in monadic do-notation.\n\n  ## Examples\n\n      iex> run(ask(), 42)\n      42\n\n      iex> use Witchcraft\n      ...>\n      ...> example_fun =\n      ...>   fn x ->\n      ...>     monad %Algae.Reader{} do\n      ...>       e <- ask()\n      ...>       return {x, e}\n      ...>     end\n      ...>   end\n      ...>\n      ...> 42\n      ...> |> example_fun.()\n      ...> |> run(7)\n      {42, 7}\n\n  \"\"\"\n  @spec ask() :: t()\n  def ask, do: Reader.new(fn x -> x end)\n\n  @doc ~S\"\"\"\n  Similar to `new/1` and `ask/0`. Construct an `Algae.Reader`,\n  but apply a function to the constructed envoronment.\n\n  The pun here is that you're \"asking\" a function for something.\n\n  ## Examples\n\n      iex> fn x -> x * 10 end\n      ...> |> ask()\n      ...> |> run(5)\n      50\n\n      iex> use Witchcraft\n      ...>\n      ...> foo =\n      ...>   fn words ->\n      ...>     monad %Algae.Reader{} do\n      ...>       loud <- ask &(&1 == String.upcase(&1))\n      ...>       return(words <> (if loud, do: \"!\", else: \".\"))\n      ...>     end\n      ...>   end\n      ...>\n      ...> \"Hello\" |> foo.() |> run(\"WORLD\") # \"WORLD\" is the context being asked for\n      \"Hello!\"\n\n  \"\"\"\n  @spec ask((any() -> any())) :: t()\n  def ask(fun) do\n    monad %Reader{} do\n      e <- ask\n      return fun.(e)\n    end\n  end\n\n  @doc \"\"\"\n  Locally composes a function into a `Reader`.\n\n  Often the idea is to temporarily adapt the `Reader` without continuing this\n  change in later `run`s.\n\n  ## Examples\n\n      iex> ask()\n      ...> |> local(fn word -> word <> \"!\" end)\n      ...> |> local(&String.upcase/1)\n      ...> |> run(\"o hai thar\")\n      \"O HAI THAR!\"\n\n  \"\"\"\n  @spec local(t(), (any() -> any())) :: any()\n  def local(reader, fun) do\n    monad %Reader{} do\n      e <- ask\n      return run(reader, fun.(e))\n    end\n  end\nend\n"
  },
  {
    "path": "lib/algae/state/applicative.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Applicative, for: Algae.State do\n  @force_type_instance true\n  def of(_, value), do: %Algae.State{runner: fn x -> {value, x} end}\nend\n"
  },
  {
    "path": "lib/algae/state/apply.ex",
    "content": "alias  Algae.State\nimport TypeClass\n\ndefinst Witchcraft.Apply, for: Algae.State do\n  @force_type_instance true\n  def convey(%State{runner: state_g}, %State{runner: state_f}) do\n    fg =\n      fn(s) ->\n        {x, t} = state_f.(s)\n        {y, u} = state_g.(t)\n        {x.(y), u}\n      end\n\n    State.new(fn x -> fg.(x) end)\n  end\nend\n"
  },
  {
    "path": "lib/algae/state/chain.ex",
    "content": "alias  Algae.State\nimport TypeClass\n\ndefinst Witchcraft.Chain, for: Algae.State do\n  @force_type_instance true\n\n  def chain(state, link) do\n    State.state(fn s ->\n      {x, z} = State.run(state, s)\n      State.run(link.(x), z)\n    end)\n  end\nend\n"
  },
  {
    "path": "lib/algae/state/functor.ex",
    "content": "alias  Algae.State\nimport TypeClass\n\ndefinst Witchcraft.Functor, for: Algae.State do\n  @force_type_instance true\n\n  def map(%State{runner: inner}, fun) do\n    run_map = fn({a, b}, f) -> {f.(a), b} end\n\n    st_tuple =\n      fn(g, s) ->\n        g\n        |> State.new()\n        |> State.run(s)\n      end\n\n    State.new(fn x ->\n      inner\n      |> st_tuple.(x)\n      |> run_map.(fun)\n    end)\n  end\nend\n"
  },
  {
    "path": "lib/algae/state/generator.ex",
    "content": "defimpl TypeClass.Property.Generator, for: Algae.State do\n  def generate(_) do\n    inner =\n      [0, 1.1, \"\", []]\n      |> Enum.random()\n      |> TypeClass.Property.Generator.generate()\n\n    Algae.State.new(fn x -> {inner, x} end)\n  end\nend\n"
  },
  {
    "path": "lib/algae/state/monad.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Monad, for: Algae.State do\n  @force_type_instance true\nend\n"
  },
  {
    "path": "lib/algae/state.ex",
    "content": "defmodule Algae.State do\n  @moduledoc ~S\"\"\"\n  `Algae.State` describes a wrapped function that can be used to pass around some\n  \"hidden\" pure state.\n\n  This has numerous applications, but the primary advantage is purity. The state\n  gets passed around with the value, and the monadic DSL helps it feel more\n  natural than passing everything around by hand.\n\n  In many ways, `Algae.State` is a generalization of `Algae.Reader` and `Algae.Writer`.\n  See [Thee Useful Monads](http://adit.io/posts/2013-06-10-three-useful-monads.html#the-state-monad)\n  a nice, illustrated guide to how these work and relate.\n\n  ## Anatomy\n\n                # To pass in concrete values\n                                ↓\n      %Algae.State{runner: fn access -> {value, state} end}\n                                           ↑      ↑\n                 # \"explicit\" value position     \"hidden\" state position\n\n  ## Examples\n\n      iex> use Witchcraft\n      ...>\n      ...> %Algae.State{}\n      ...> |> monad do\n      ...>   name <- get()\n      ...>   let result = \"Hello, #{name}!\"\n      ...>\n      ...>   put result\n      ...>   modify &String.upcase/1\n      ...>\n      ...>   return result\n      ...> end\n      ...> |> run(\"world\")\n      {\n        \"Hello, world!\",\n        \"HELLO, WORLD!\"\n      }\n\n      iex> use Witchcraft\n      ...>\n      ...> pop  = fn -> state(fn([x | xs])       -> {x, xs}   end) end\n      ...> pull = fn -> state(fn(list = [x | _]) -> {x, list} end) end\n      ...> push = &state(fn(xs) -> {%Witchcraft.Unit{}, [&1 | xs]} end)\n      ...>\n      ...> %Algae.State{}\n      ...> |> monad do\n      ...>   push.([\"a\"])\n      ...>   push.([\"b\"])\n      ...>   push.([\"c\"])\n      ...>   push.([\"d\"])\n      ...>   push.([\"e\"])\n      ...>\n      ...>   z <- pop.()\n      ...>   y <- pop.()\n      ...>   x <- pop.()\n      ...>\n      ...>   push.(x <> y <> z)\n      ...>   pull.()\n      ...> end\n      ...> |> evaluate([])\n      [\"c\", \"d\", \"e\"]\n\n  \"\"\"\n\n  alias __MODULE__\n  alias Witchcraft.Unit\n\n  use Witchcraft\n\n  @type runner :: (any() -> {any(), any()})\n  @type t :: %State{runner: runner()}\n\n  defstruct [runner: &State.default/1]\n\n  @spec default(any()) :: {integer(), any()}\n  def default(s), do: {s, s}\n\n  @doc \"\"\"\n  Construct a new `Algae.State` struct from a state runner in the form\n  `fn x -> {y, z} end`\n\n  ## Examples\n\n      iex> new(fn x -> {x + 1, x} end).runner.(42)\n      {43, 42}\n\n  \"\"\"\n  @spec new(State.runner()) :: State.t()\n  def new(runner), do: %State{runner: runner}\n\n  @doc \"\"\"\n  Alias for `new/1` that reads better when importing the module.\n\n  ## Examples\n\n      iex> state(fn x -> {x + 1, x} end).runner.(42)\n      {43, 42}\n\n  \"\"\"\n  @spec state(State.runner()) :: State.t()\n  def state(runner), do: new(runner)\n\n  @doc \"\"\"\n  Extract the runner from an `Algae.State`.\n\n  Can be used as a curried version of `run/2`.\n\n  ## Examples\n\n      iex> inner = fn x -> {0, x} end\n      ...>\n      ...> run(%Algae.State{runner: inner}).(42) == inner.(42)\n      true\n\n  \"\"\"\n  @spec run(State.t()) :: State.runner()\n  def run(%State{runner: fun}), do: fun\n\n  @doc \"\"\"\n  Run an `Algae.State` by passing in some initial state to actualy run the enclosed\n  state runner.\n\n  ## Examples\n\n      iex> use Witchcraft\n      ...>\n      ...> %Algae.State{}\n      ...> |> of(2)\n      ...> |> run(0)\n      {2, 0}\n\n  \"\"\"\n  @spec run(State.t(), any()) :: any()\n  def run(%State{runner: fun}, arg), do: fun.(arg)\n\n  @doc \"\"\"\n  Set the stateful position of an `Algae.Struct`.\n\n  Not unlike `Algae.Writer.tell/1`.\n\n  ## Examples\n\n      iex> 1\n      ...> |> put()\n      ...> |> run(0)\n      {%Witchcraft.Unit{}, 1}\n\n  \"\"\"\n  @spec put(any()) :: State.t()\n  def put(s), do: State.new(fn _ -> {%Unit{}, s} end)\n\n  @doc ~S\"\"\"\n  Run a function over the \"state\" portion of the runner.\n\n  ## Examples\n\n      iex> fn x -> x + 1 end\n      ...> |> modify()\n      ...> |> run(42)\n      {%Witchcraft.Unit{}, 43}\n\n      iex> use Witchcraft\n      ...>\n      ...> %Algae.State{}\n      ...> |> monad do\n      ...>   name <- get()\n      ...>\n      ...>   put \"State\"\n      ...>   modify &String.upcase/1\n      ...>\n      ...>   return \"Hello, #{name}!\"\n      ...> end\n      ...> |> run(\"world\")\n      {\"Hello, world!\", \"STATE\"}\n\n  \"\"\"\n  @spec modify((any() -> any())) :: State.t()\n  def modify(fun), do: State.new(fn s -> {%Unit{}, fun.(s)} end)\n\n  @doc \"\"\"\n  Set both sides of an `Algae.State` struct.\n\n  ## Examples\n\n      iex> run(get(), 1)\n      {1, 1}\n\n  \"\"\"\n  @spec get() :: State.t()\n  def get, do: State.new(fn a -> {a, a} end)\n\n  @doc \"\"\"\n  Set both sides of an `Algae.State` struct, plus running a function over the\n  value portion of the inner state.\n\n  ## Examples\n\n      iex> fn x -> x * 10 end\n      ...> |> get()\n      ...> |> run(4)\n      {40, 4}\n\n  \"\"\"\n  @spec get((any() -> any())) :: State.t()\n  def get(fun) do\n    monad %Algae.State{} do\n      s <- get()\n      return fun.(s)\n    end\n  end\n\n  @doc ~S\"\"\"\n  Run the enclosed `Algae.State` runner, and return the value (no state).\n\n  ## Examples\n\n      iex> use Witchcraft\n      ...>\n      ...> %Algae.State{}\n      ...> |> monad do\n      ...>   name <- get()\n      ...>   put \"Ignored\"\n      ...>   return \"Hello, #{name}!\"\n      ...> end\n      ...> |> evaluate(\"world\")\n      \"Hello, world!\"\n\n  \"\"\"\n  @spec evaluate(State.t(), any()) :: any()\n  def evaluate(state, value) do\n    state\n    |> run(value)\n    |> elem(0)\n  end\n\n  @doc ~S\"\"\"\n  Run the enclosed `Algae.State` runner, and return the state (no value).\n\n  ## Examples\n\n      iex> fn x -> x + 1 end\n      ...> |> get()\n      ...> |> execute(1)\n      1\n\n      iex> use Witchcraft\n      ...>\n      ...> %Algae.State{}\n      ...> |> monad do\n      ...>   whatevs <- get()\n      ...>   put \"State\"\n      ...>   return \"Hello, #{whatevs}!\"\n      ...> end\n      ...> |> execute(\"world\")\n      \"State\"\n\n  \"\"\"\n  @spec execute(State.t(), any()) :: any()\n  def execute(state, value) do\n    state\n    |> run(value)\n    |> elem(1)\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/applicative.ex",
    "content": "alias Algae.Tree.BinarySearch.Node\nimport TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Applicative, for: Algae.Tree.BinarySearch.Empty do\n  def of(_, data), do: %Node{node: data}\nend\n\ndefinst Witchcraft.Applicative, for: Algae.Tree.BinarySearch.Node do\n  @force_type_instance true\n  def of(_, data), do: %Node{node: data}\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/apply.ex",
    "content": "alias Algae.Tree.BinarySearch.{Empty, Node}\nimport TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Apply, for: Algae.Tree.BinarySearch.Empty do\n  def convey(_, _), do: %Empty{}\nend\n\ndefinst Witchcraft.Apply, for: Algae.Tree.BinarySearch.Node do\n  def convey(_, %Empty{}), do: %Empty{}\n  def convey(%{node: node, left: left, right: right}, tree_funs = %Node{node: fun}) do\n    %Node{\n      node:  fun.(node),\n      left:  Witchcraft.Apply.convey(left,  tree_funs),\n      right: Witchcraft.Apply.convey(right, tree_funs)\n    }\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/chain.ex",
    "content": "alias Algae.Tree.BinarySearch.{Empty, Node}\nimport TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Chain, for: Algae.Tree.BinarySearch.Empty do\n  def chain(_, _), do: %Empty{}\nend\n\ndefinst Witchcraft.Chain, for: Algae.Tree.BinarySearch.Node do\n  def chain(%Node{node: node}, link), do: link.(node)\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/extend.ex",
    "content": "alias Algae.Tree.BinarySearch.{Empty, Node}\nimport TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Extend, for: Algae.Tree.BinarySearch.Empty do\n  def nest(_), do: %Empty{}\nend\n\ndefinst Witchcraft.Extend, for: Algae.Tree.BinarySearch.Node do\n  def nest(tree = %Node{left: left, right: right}) do\n    %Node{\n      node:  tree,\n      left:  Witchcraft.Extend.nest(left),\n      right: Witchcraft.Extend.nest(right)\n    }\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/foldable.ex",
    "content": "alias Algae.Tree.BinarySearch.Node\nimport TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Foldable, for: Algae.Tree.BinarySearch.Empty do\n  def right_fold(_, seed, _), do: seed\nend\n\ndefinst Witchcraft.Foldable, for: Algae.Tree.BinarySearch.Node do\n  def right_fold(%Node{node: node, left: left, right: right}, seed, fun) do\n    folded_right = Witchcraft.Foldable.right_fold(right, seed,         fun)\n    folded_left  = Witchcraft.Foldable.right_fold(left,  folded_right, fun)\n\n    fun.(node, folded_left)\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/functor.ex",
    "content": "alias  Algae.Tree.BinarySearch.{Empty, Node}\nalias  Witchcraft.Functor\nimport TypeClass\n\ndefinst Witchcraft.Functor, for: Algae.Tree.BinarySearch.Empty do\n  def map(_, _), do: %Empty{}\nend\n\ndefinst Witchcraft.Functor, for: Algae.Tree.BinarySearch.Node do\n  def map(%Node{node: node, left: left, right: right}, fun) do\n    %Node{\n      node:  fun.(node),\n      left:  Functor.map(left,  fun),\n      right: Functor.map(right, fun)\n    }\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/generator.ex",
    "content": "alias Algae.Tree.BinarySearch.{Empty, Node}\nuse Witchcraft\n\ndefimpl TypeClass.Property.Generator, for: Algae.Tree.BinarySearch.Empty do\n  def generate(_), do: Empty.new()\nend\n\ndefimpl TypeClass.Property.Generator, for: Algae.Tree.BinarySearch.Node do\n  def generate(_) do\n    random_node()\n  end\n\n  def random_node do\n    case Enum.random(Enum.to_list(0..5)) do\n      0 ->\n        %Node{node: random_value()}\n\n      1 ->\n        %Node{node: random_value()}\n\n      2 ->\n        %Node{\n          node:  random_value(),\n          left:  random_node(),\n          right: random_node()\n    }\n\n      _ ->\n        %Empty{}\n    end\n  end\n\n  def random_value do\n    [1, 1.1, \"\", []]\n    |> Enum.random()\n    |> TypeClass.Property.Generator.generate()\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/monad.ex",
    "content": "import TypeClass\nuse Witchcraft\n\ndefinst(Witchcraft.Monad, for: Algae.Tree.BinarySearch.Empty)\n\ndefinst Witchcraft.Monad, for: Algae.Tree.BinarySearch.Node do\n  @force_type_instance true\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/monoid.ex",
    "content": "alias Algae.Tree.BinarySearch, as: BST\nalias Algae.Tree.BinarySearch.{Empty, Node}\n\nimport TypeClass\n\nuse Witchcraft\n\ndefinst Witchcraft.Monoid, for: Algae.Tree.BinarySearch.Empty do\n  def empty(empty), do: empty\nend\n\ndefinst Witchcraft.Monoid, for: Algae.Tree.BinarySearch.Node do\n  def empty(_), do: %Empty{}\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/ord.ex",
    "content": "alias Algae.Tree.BinarySearch.{Empty, Node}\nimport TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Ord, for: Algae.Tree.BinarySearch.Empty do\n  def compare(_, %Empty{}), do: :equal\n  def compare(_, %Node{}),  do: :lesser\nend\n\ndefinst Witchcraft.Ord, for: Algae.Tree.BinarySearch.Node do\n  custom_generator(_) do\n    random_node()\n  end\n\n  def random_node do\n    Enum.random([\n      %Empty{},\n      %Empty{},\n      %Empty{},\n      %Node{\n        node: random_value()\n      },\n      %Node{\n        node:  random_value(),\n        left:  random_value(),\n        right: random_value()\n      }\n    ])\n  end\n\n  def random_value, do: TypeClass.Property.Generator.generate(1)\n\n  def compare(%Node{}, %Empty{}), do: :greater\n  def compare(%Node{node: a}, %Node{node: b}), do: Witchcraft.Ord.compare(a, b)\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/semigroup.ex",
    "content": "alias Algae.Tree.BinarySearch, as: BST\nalias Algae.Tree.BinarySearch.{Empty, Node}\n\nimport TypeClass\nuse Witchcraft\n\ndefinst Witchcraft.Semigroup, for: Algae.Tree.BinarySearch.Empty do\n  def append(_, %Empty{}), do: %Empty{}\n  def append(_, node = %Node{}), do: node\nend\n\ndefinst Witchcraft.Semigroup, for: Algae.Tree.BinarySearch.Node do\n  def append(node, %Empty{}), do: node\n\n  def append(node_a, node_b) do\n    node_a\n    |> BST.to_list()\n    |> Enum.concat(BST.to_list(node_b))\n    |> BST.from_list()\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search/setoid.ex",
    "content": "alias Algae.Tree.BinarySearch, as: BST\nalias Algae.Tree.BinarySearch.{Empty, Node}\n\nimport TypeClass\n\nuse Witchcraft\n\ndefinst Witchcraft.Setoid, for: Algae.Tree.BinarySearch.Empty do\n  def equivalent?(_, %Empty{}), do: true\n  def equivalent?(_, %Node{}),  do: false\nend\n\ndefinst Witchcraft.Setoid, for: Algae.Tree.BinarySearch.Node do\n  def equivalent?(%Node{}, %Empty{}), do: false\n  def equivalent?(%Node{node: a}, %Node{node: b}) do\n    Witchcraft.Setoid.equivalent?(a, b)\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/binary_search.ex",
    "content": "defmodule Algae.Tree.BinarySearch do\n  @moduledoc \"\"\"\n  Represent a `BinarySearch` tree.\n\n  ## Examples\n\n      iex> alias Algae.Tree.BinarySearch, as: BSTree\n      ...>\n      ...> BSTree.Node.new(\n      ...>   42,\n      ...>   BSTree.Node.new(77),\n      ...>   BSTree.Node.new(\n      ...>     1234,\n      ...>     BSTree.Node.new(98),\n      ...>     BSTree.Node.new(32)\n      ...>   )\n      ...> )\n      %Algae.Tree.BinarySearch.Node{\n        node: 42,\n        left: %Algae.Tree.BinarySearch.Node{\n          node:  77,\n          left:  %Algae.Tree.BinarySearch.Empty{},\n          right: %Algae.Tree.BinarySearch.Empty{}\n        },\n        right: %Algae.Tree.BinarySearch.Node{\n          node:  1234,\n          left:  %Algae.Tree.BinarySearch.Node{\n            node:  98,\n            left:  %Algae.Tree.BinarySearch.Empty{},\n            right: %Algae.Tree.BinarySearch.Empty{}\n          },\n          right: %Algae.Tree.BinarySearch.Node{\n            node:  32,\n            left:  %Algae.Tree.BinarySearch.Empty{},\n            right: %Algae.Tree.BinarySearch.Empty{}\n          }\n        }\n      }\n\n  \"\"\"\n\n  alias __MODULE__\n  alias BinarySearch.{Empty, Node}\n\n  import Algae\n  use Witchcraft, except: [to_list: 1]\n\n  defsum do\n    defdata(Empty :: none())\n\n    defdata Node do\n      node :: any()\n      left :: BinarySearch.t() \\\\ BinarySearch.Empty.new()\n      right :: BinarySearch.t() \\\\ BinarySearch.Empty.new()\n    end\n  end\n\n  @doc \"\"\"\n  Create an empty tree.\n\n  ## Examples\n\n      iex> new()\n      %Algae.Tree.BinarySearch.Empty{}\n\n  \"\"\"\n  @spec new() :: Empty.t()\n  def new, do: %Empty{}\n\n  @doc \"\"\"\n  Bring a value into an otherwise empty tree.\n\n  ## Examples\n\n      iex> new(42)\n      %Algae.Tree.BinarySearch.Node{\n        node:  42,\n        left:  %Algae.Tree.BinarySearch.Empty{},\n        right: %Algae.Tree.BinarySearch.Empty{}\n      }\n\n  \"\"\"\n  @spec new(any()) :: Node.t()\n  def new(value), do: %Node{node: value}\n\n  @doc \"\"\"\n  Insert a new element into a tree.\n\n  ## Examples\n\n      iex> insert(new(42), 43)\n      %Algae.Tree.BinarySearch.Node{\n        node: 42,\n        right: %Algae.Tree.BinarySearch.Node{\n          node: 43\n        }\n      }\n\n  \"\"\"\n  @spec insert(t(), any()) :: t()\n  def insert(%Empty{}, value), do: new(value)\n\n  def insert(tree = %Node{node: node, left: left, right: right}, orderable) do\n    case compare(orderable, node) do\n      :equal -> tree\n      :greater -> %{tree | right: insert(right, orderable)}\n      :lesser -> %{tree | left: insert(left, orderable)}\n    end\n  end\n\n  def insert(%Empty{}, value), do: new(value)\n\n  def insert(tree = %Node{node: node, left: left, right: right}, orderable) do\n    case compare(orderable, node) do\n      :equal -> tree\n      :greater -> %{tree | right: insert(right, orderable)}\n      :lesser -> %{tree | left: insert(left, orderable)}\n    end\n  end\n\n  @doc \"\"\"\n  Remove an element from a tree by value.\n\n  ## Examples\n\n      iex> alias Algae.Tree.BinarySearch, as: BSTree\n      ...>\n      ...> BSTree.Node.new(\n      ...>   42,\n      ...>   BSTree.Node.new(77),\n      ...>   BSTree.Node.new(\n      ...>     1234,\n      ...>     BSTree.Node.new(98),\n      ...>     BSTree.Node.new(32)\n      ...>   )\n      ...> ) |> delete(98)\n      %Algae.Tree.BinarySearch.Node{\n        node: 42,\n        left: %Algae.Tree.BinarySearch.Node{\n          node: 77\n        },\n        right: %Algae.Tree.BinarySearch.Node{\n          node: 1234,\n          right: %Algae.Tree.BinarySearch.Node{\n            node: 32\n          }\n        }\n      }\n\n  \"\"\"\n  @spec delete(t(), any()) :: t()\n  def delete(%Empty{}, _), do: %Empty{}\n\n  def delete(tree = %Node{node: node, left: left, right: right}, orderable) do\n    case compare(orderable, node) do\n      :greater ->\n        %{tree | right: delete(right, orderable)}\n\n      :lesser ->\n        %{tree | left: delete(left, orderable)}\n\n      :equal ->\n        case tree do\n          %{left: %Empty{}} -> right\n          %{right: %Empty{}} -> left\n          %{right: %{node: shift}} -> %{tree | node: shift, right: delete(right, shift)}\n        end\n    end\n  end\n\n  @doc \"\"\"\n  Flatten a tree into a list.\n\n  ## Examples\n\n      iex> alias Algae.Tree.BinarySearch, as: BSTree\n      ...>\n      ...> BSTree.Node.new(\n      ...>   42,\n      ...>   BSTree.Node.new(77),\n      ...>   BSTree.Node.new(\n      ...>     1234,\n      ...>     BSTree.Node.new(98),\n      ...>     BSTree.Node.new(32)\n      ...>   )\n      ...> )\n      ...> |> BSTree.to_list()\n      [42, 77, 1234, 98, 32]\n\n  \"\"\"\n  @spec to_list(t()) :: list()\n  def to_list(tree), do: Witchcraft.Foldable.to_list(tree)\n\n  @doc \"\"\"\n  Flatten a tree into a list with elements sorted.\n\n  ## Examples\n\n      iex> alias Algae.Tree.BinarySearch, as: BSTree\n      ...>\n      ...> BSTree.Node.new(\n      ...>   42,\n      ...>   BSTree.Node.new(77),\n      ...>   BSTree.Node.new(\n      ...>     1234,\n      ...>     BSTree.Node.new(98),\n      ...>     BSTree.Node.new(32)\n      ...>   )\n      ...> )\n      ...> |> BSTree.to_ordered_list()\n      [32, 42, 77, 98, 1234]\n\n  \"\"\"\n  @spec to_ordered_list(t()) :: list()\n  def to_ordered_list(tree), do: tree |> to_list() |> Enum.sort()\n\n  @doc \"\"\"\n  Build a `BinarySearch` tree from a list.\n\n  ## Examples\n\n      iex> Algae.Tree.BinarySearch.from_list([42, 77, 1234, 98, 32])\n      %Algae.Tree.BinarySearch.Node{\n        node: 42,\n        left: %Algae.Tree.BinarySearch.Node{\n          node:  32\n        },\n        right: %Algae.Tree.BinarySearch.Node{\n          node: 77,\n          right: %Algae.Tree.BinarySearch.Node{\n            node: 1234,\n            left: %Algae.Tree.BinarySearch.Node{\n              node:  98\n            }\n          }\n        }\n      }\n\n  \"\"\"\n  @spec from_list(list()) :: t()\n  def from_list([]), do: %Empty{}\n  def from_list([head | tail]), do: from_list(tail, new(head))\n\n  @doc \"\"\"\n  Build a `BinarySearch` tree from a list and attach to an existing tree.\n\n  ## Examples\n\n      iex> Algae.Tree.BinarySearch.from_list([42, 77, 1234, 98, 32], new(-9))\n      %Algae.Tree.BinarySearch.Node{\n        node:  -9,\n        right: %Algae.Tree.BinarySearch.Node{\n          left: %Algae.Tree.BinarySearch.Node{\n            node:  32\n          },\n          node: 42,\n          right: %Algae.Tree.BinarySearch.Node{\n            node: 77,\n            right: %Algae.Tree.BinarySearch.Node{\n              node: 1234,\n              left: %Algae.Tree.BinarySearch.Node{\n                node: 98\n              },\n              right: %Algae.Tree.BinarySearch.Empty{}\n            }\n          }\n        }\n      }\n\n  \"\"\"\n  @spec from_list(list(), t()) :: t()\n  def from_list([], seed), do: seed\n  def from_list([head | tail], seed), do: from_list(tail, insert(seed, head))\nend\n"
  },
  {
    "path": "lib/algae/tree/rose/applicative.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Applicative, for: Algae.Tree.Rose do\n  def of(_, value), do: Algae.Tree.Rose.new(value)\nend\n"
  },
  {
    "path": "lib/algae/tree/rose/apply.ex",
    "content": "alias  Algae.Tree.Rose\nalias  Witchcraft.{Apply, Functor}\nimport TypeClass\n\ndefinst Witchcraft.Apply, for: Algae.Tree.Rose do\n  def convey(tree = %Rose{rose: rose, forest: forest}, %Rose{rose: fun, forest: funs}) do\n    new_forest =\n         Functor.map(forest, &Functor.map(&1, fun))\n      ++ Functor.map(funs,   &Apply.convey(tree, &1))\n\n    %Rose{\n      rose:   fun.(rose),\n      forest: new_forest\n    }\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/rose/chain.ex",
    "content": "alias  Algae.Tree.Rose\nalias  Witchcraft.{Chain, Functor}\nimport TypeClass\n\ndefinst Witchcraft.Chain, for: Algae.Tree.Rose do\n  def chain(%Rose{rose: rose, forest: forest}, link) do\n    %Rose{rose: new_rose, forest: mid_forest} = link.(rose)\n\n    new_forest = mid_forest ++ Functor.map(forest, &Chain.chain(&1, link))\n\n    Rose.new(new_rose, new_forest)\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/rose/foldable.ex",
    "content": "alias  Algae.Tree.Rose\nalias  Witchcraft.Foldable\nimport TypeClass\n\ndefinst Witchcraft.Foldable, for: Algae.Tree.Rose do\n  def right_fold(%Rose{rose: rose, forest: forest}, acc, fun) do\n    fun.(rose, Foldable.right_fold(forest, acc, fun))\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/rose/functor.ex",
    "content": "alias  Algae.Tree.Rose\nalias  Witchcraft.Functor\nimport TypeClass\n\ndefinst Witchcraft.Functor, for: Algae.Tree.Rose do\n  def map(%Rose{rose: rose, forest: forest}, fun) do\n    %Rose{\n      rose:   fun.(rose),\n      forest: Functor.map(forest, &Functor.map(&1, fun))\n    }\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/rose/generator.ex",
    "content": "alias  Algae.Tree.Rose\nalias  TypeClass.Property.Generator\n\ndefimpl TypeClass.Property.Generator, for: Algae.Tree.Rose do\n  def generate(_) do\n    case Enum.random(0..2) do\n      0 -> Rose.new(rose(), forest())\n      _ -> Rose.new(rose())\n    end\n  end\n\n  def forest do\n    fn ->\n      case Enum.random(0..10) do\n        0 -> Rose.new(rose(), forest())\n        _ -> Rose.new(rose())\n      end\n    end\n    |> Stream.repeatedly()\n    |> Enum.take(Enum.random(0..5))\n  end\n\n  def rose do\n    [1, 1.1, \"\", []]\n    |> Enum.random()\n    |> Generator.generate()\n  end\nend\n"
  },
  {
    "path": "lib/algae/tree/rose/monad.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Monad, for: Algae.Tree.Rose\n"
  },
  {
    "path": "lib/algae/tree/rose.ex",
    "content": "defmodule Algae.Tree.Rose do\n  @moduledoc \"\"\"\n  A tree with any number of nodes at each level\n\n  ## Examples\n\n      %Algae.Tree.Rose{\n        rose: 42,\n        forest: [\n          %Algae.Tree.Rose{\n            rose: \"hi\"\n          },\n          %Algae.Tree.Rose{\n            forest: [\n              %Algae.Tree.Rose{\n                rose: 0.4\n              }\n            ]\n          },\n          %Algae.Tree.Rose{\n            rose: \"there\"\n          }\n        ]\n      }\n\n  \"\"\"\n\n  alias  __MODULE__\n  import Algae\n\n  @type rose :: any()\n  @type forest :: [t()]\n\n  defdata do\n    rose    :: any()\n    forest :: [t()]\n  end\n\n  @doc \"\"\"\n  Create a simple `Algae.Rose` tree, with an empty forest and one rose.\n\n  ## Examples\n\n      iex> new(42)\n      %Algae.Tree.Rose{\n        rose: 42,\n        forest: []\n      }\n\n  \"\"\"\n  @spec new(rose()) :: t()\n  def new(rose), do: %Rose{rose: rose, forest: []}\n\n  @doc \"\"\"\n  Create an `Algae.Rose` tree, passing a forest and a rose.\n\n  ## Examples\n\n      iex> new(42, [new(55), new(14)])\n      %Algae.Tree.Rose{\n        rose: 42,\n        forest: [\n          %Algae.Tree.Rose{rose: 55},\n          %Algae.Tree.Rose{rose: 14}\n        ]\n      }\n\n  \"\"\"\n  @spec new(rose(), forest()) :: t()\n  def new(rose, forest), do: %Rose{rose: rose, forest: forest}\n\n  @doc \"\"\"\n  Wrap another tree around an existing one, relegating it to the forest.\n\n  ## Examples\n\n      iex> 55\n      ...> |> new()\n      ...> |> layer(42)\n      ...> |> layer(99)\n      ...> |> layer(6)\n      %Algae.Tree.Rose{\n        rose: 6,\n        forest: [\n          %Algae.Tree.Rose{\n            rose: 99,\n            forest: [\n              %Algae.Tree.Rose{\n                rose: 42,\n                forest: [\n                  %Algae.Tree.Rose{\n                    rose: 55\n                  }\n                ]\n              }\n            ]\n          }\n        ]\n      }\n\n  \"\"\"\n  @spec layer(t(), rose()) :: t()\n  def layer(tree, rose), do: %Rose{rose: rose, forest: [tree]}\nend\n"
  },
  {
    "path": "lib/algae/writer/applicative.ex",
    "content": "alias  Algae.Writer\nimport TypeClass\nuse    Witchcraft\n\ndefinst Witchcraft.Applicative, for: Algae.Writer do\n  def of(%Writer{writer: {_, log}}, value), do: Writer.new(value, empty(log))\nend\n"
  },
  {
    "path": "lib/algae/writer/apply.ex",
    "content": "alias  Algae.Writer\nimport TypeClass\n\nuse Quark\nuse Witchcraft\n\ndefinst Witchcraft.Apply, for: Algae.Writer do\n  def convey(%Writer{writer: {value, log_a}}, %Writer{writer: {fun, log_b}}) do\n    Writer.new(fun.(value), log_b <> log_a)\n  end\nend\n"
  },
  {
    "path": "lib/algae/writer/chain.ex",
    "content": "alias  Algae.Writer\nimport TypeClass\nuse    Witchcraft\n\ndefinst Witchcraft.Chain, for: Algae.Writer do\n  def chain(%Writer{writer: {old_value, old_log}}, link) do\n    %Writer{writer: {new_value, new_log}} = link.(old_value)\n    Writer.new(new_value, old_log <> new_log)\n  end\nend\n"
  },
  {
    "path": "lib/algae/writer/functor.ex",
    "content": "alias  Algae.Writer\nimport TypeClass\nuse    Witchcraft\n\ndefinst Witchcraft.Functor, for: Algae.Writer do\n  def map(%Writer{writer: {value, log}}, fun), do: Writer.new(fun.(value), log)\nend\n"
  },
  {
    "path": "lib/algae/writer/generator.ex",
    "content": "alias TypeClass.Property.Generator\n\ndefimpl TypeClass.Property.Generator, for: Algae.Writer do\n  def generate(_), do: Algae.Writer.new({Generator.generate(0), Generator.generate(\"\")})\nend\n"
  },
  {
    "path": "lib/algae/writer/monad.ex",
    "content": "import TypeClass\n\ndefinst Witchcraft.Monad, for: Algae.Writer\n"
  },
  {
    "path": "lib/algae/writer.ex",
    "content": "defmodule Algae.Writer do\n  @moduledoc ~S\"\"\"\n  `Algae.Writer` helps capture the pattern of writing to a pure log or accumulated\n  value, handling the bookkeeping for you.\n\n  If `Algae.Reader` is quasi-read-only, `Algae.Writer` is quasi-write-only.\n  This is often used for loggers, but could be anything as long as the hidden value\n  is a `Witchcraft.Monoid`.\n\n  There are many applications of `Writer`s, but as an illustrative point,\n  one could use it for logging across processes and time, since the log\n  is carried around with the result in a pure fashion. The monadic DSL\n  helps make using these feel more natural.\n\n  For an illustrated guide to `Writer`s,\n  see [Thee Useful Monads](http://adit.io/posts/2013-06-10-three-useful-monads.html#the-state-monad).\n\n  ## Anatomy\n\n        %Algae.Writer{writer: {value, log}}\n                                 ↑     ↑\n       # \"explicit\" value position    \"hidden\" position,\n       #                               commonly used as a log\n\n  ## Examples\n\n      iex> use Witchcraft\n      ...>\n      ...> excite =\n      ...>   fn string ->\n      ...>     monad writer({0.0, \"log\"}) do\n      ...>       tell string\n      ...>\n      ...>       excited <- return \"#{string}!\"\n      ...>       tell \" => #{excited} ... \"\n      ...>\n      ...>       return excited\n      ...>     end\n      ...>   end\n      ...>\n      ...> {_, logs} =\n      ...>   \"Hi\"\n      ...>   |> excite.()\n      ...>   >>> excite\n      ...>   >>> excite\n      ...>   |> censor(&String.trim_trailing(&1, \" ... \"))\n      ...>   |> run()\n      ...>\n      ...> logs\n      \"Hi => Hi! ... Hi! => Hi!! ... Hi!! => Hi!!!\"\n\n      iex> use Witchcraft\n      ...>\n      ...> exponent =\n      ...>   fn num ->\n      ...>     monad writer({0, 0}) do\n      ...>       tell 1\n      ...>       return num * num\n      ...>     end\n      ...>   end\n      ...>\n      ...> initial = 42\n      ...> {result, times} = run(exponent.(initial) >>> exponent >>> exponent)\n      ...>\n      ...> \"#{initial}^#{round(:math.pow(2, times))} = #{result}\"\n      \"42^8 = 9682651996416\"\n\n  \"\"\"\n\n  alias __MODULE__\n  alias Witchcraft.{Monoid, Unit}\n  use   Witchcraft\n\n  @type log    :: Monoid.t()\n  @type value  :: any()\n  @type writer :: {Writer.value(), Writer.log()}\n\n  @type t :: %Writer{writer: writer()}\n\n  defstruct writer: {0, []}\n\n  @doc \"\"\"\n  Construct a `Algae.Writer` struct from a starting value and log.\n\n  ## Examples\n\n      iex> new()\n      %Algae.Writer{writer: {0, []}}\n\n      iex> new(\"hi\")\n      %Algae.Writer{writer: {\"hi\", []}}\n\n      iex> new(\"ohai\", 42)\n      %Algae.Writer{writer: {\"ohai\", 42}}\n\n  \"\"\"\n  @spec new(any(), Monoid.t()) :: Writer.t()\n  def new(value \\\\ 0, log \\\\ []), do: %Writer{writer: {value, log}}\n\n  @doc \"\"\"\n  Similar to `new/2`, but taking a tuple rather than separate fields.\n\n  ## Examples\n\n      iex> writer({\"ohai\", 42})\n      %Algae.Writer{writer: {\"ohai\", 42}}\n\n  \"\"\"\n  @spec writer(Writer.writer()) :: Writer.t()\n  def writer({value, log}), do: new(value, log)\n\n  @doc ~S\"\"\"\n  Extract the enclosed value and log from an `Algae.Writer`.\n\n  ## Examples\n\n      iex> run(%Algae.Writer{writer: {\"hi\", \"there\"}})\n      {\"hi\", \"there\"}\n\n      iex> use Witchcraft\n      ...>\n      ...> half =\n      ...>   fn num ->\n      ...>     monad writer({0.0, [\"log\"]}) do\n      ...>       let half = num / 2\n      ...>       tell [\"#{num} / 2 = #{half}\"]\n      ...>       return half\n      ...>     end\n      ...>   end\n      ...>\n      ...> run(half.(42) >>> half >>> half)\n      {\n        5.25,\n        [\n          \"42 / 2 = 21.0\",\n          \"21.0 / 2 = 10.5\",\n          \"10.5 / 2 = 5.25\"\n        ]\n      }\n\n  \"\"\"\n  @spec run(Writer.t()) :: Writer.value()\n  def run(%Writer{writer: writer}), do: writer\n\n  @doc ~S\"\"\"\n  Set the \"log\" portion of an `Algae.Writer` step\n\n  ## Examples\n\n      iex> tell(\"secrets\")\n      %Algae.Writer{writer: {%Witchcraft.Unit{}, \"secrets\"}}\n\n      iex> use Witchcraft\n      ...>\n      ...> monad %Algae.Writer{writer: {\"string\", 1}} do\n      ...>   tell 42\n      ...>   tell 43\n      ...>   return \"hey\"\n      ...> end\n      %Algae.Writer{writer: {\"hey\", 85}}\n\n      iex> use Witchcraft\n      ...>\n      ...> half =\n      ...>   fn num ->\n      ...>     monad writer({0.0, [\"log\"]}) do\n      ...>       let half = num / 2\n      ...>       tell [\"#{num} / 2 = #{half}\"]\n      ...>       return half\n      ...>     end\n      ...>   end\n      ...>\n      ...> run(half.(42.0) >>> half >>> half)\n      {\n        5.25,\n        [\n          \"42.0 / 2 = 21.0\",\n          \"21.0 / 2 = 10.5\",\n          \"10.5 / 2 = 5.25\"\n        ]\n      }\n\n  \"\"\"\n  @spec tell(Writer.log()) :: Writer.t()\n  def tell(log), do: new(%Unit{}, log)\n\n  @doc \"\"\"\n  Copy the log into the value position. This makes it accessible in do-notation.\n\n  ## Examples\n\n      iex> listen(%Algae.Writer{writer: {42, \"hi\"}})\n      %Algae.Writer{writer: {{42, \"hi\"}, \"hi\"}}\n\n      iex> use Witchcraft\n      ...>\n      ...> monad new(1, 1) do\n      ...>   wr <- listen tell(42)\n      ...>   tell 43\n      ...>   return wr\n      ...> end\n      %Algae.Writer{\n        writer: {{%Witchcraft.Unit{}, 42}, 85}\n      }\n\n  \"\"\"\n  @spec listen(Writer.t()) :: Writer.t()\n  def listen(%Writer{writer: {value, log}}), do: %Writer{writer: {{value, log}, log}}\n\n  @doc \"\"\"\n  Similar to `listen/1`, but with the ability to adjust the copied log.\n\n  ## Examples\n\n      iex> listen(%Algae.Writer{writer: {1, \"hi\"}}, &String.upcase/1)\n      %Algae.Writer{\n        writer: {{1, \"HI\"}, \"hi\"}\n      }\n\n  \"\"\"\n  @spec listen(Writer.t(), (log() -> log())) :: Writer.t()\n  def listen(writer, fun) do\n    monad writer do\n      {value, log} <- listen writer\n      return {value, fun.(log)}\n    end\n  end\n\n  @doc ~S\"\"\"\n  Run a function in the value portion of an `Algae.Writer` on the log.\n\n  Notice that the structure is similar to what somes out of `listen/{1,2}`\n\n      Algae.Writer{writer: {{_, function}, log}}\n\n  ## Examples\n\n      iex> pass(%Algae.Writer{writer: {{1, fn x -> x * 10 end}, 42}})\n      %Algae.Writer{writer: {1, 420}}\n\n      iex> use Witchcraft\n      ...>\n      ...> monad new(\"string\", [\"logs\"]) do\n      ...>   a <-  [\"start\"] |> tell() |> listen()\n      ...>   tell [\"middle\"]\n      ...>\n      ...>   {value, logs} <- return a\n      ...>   pass writer({{value, fn [log | _] -> [log | [log | logs]] end}, logs})\n      ...>\n      ...>   tell [\"next is 42\"]\n      ...>   return 42\n      ...> end\n      %Algae.Writer{\n        writer: {42, [\"start\", \"middle\", \"start\", \"start\", \"start\", \"next is 42\"]}\n      }\n\n  \"\"\"\n  @spec pass(Writer.t()) :: Writer.t()\n  def pass(%Writer{writer: {{value, fun}, log}}), do: %Writer{writer: {value, fun.(log)}}\n\n  @doc ~S\"\"\"\n  Run a writer, and run a function over the resulting log.\n\n  ## Examples\n\n      iex> 42\n      ...> |> new([\"hi\", \"THERE\", \"friend\"])\n      ...> |> censor(&Enum.reject(&1, fn log -> String.upcase(log) == log end))\n      ...> |> run()\n      {42, [\"hi\", \"friend\"]}\n\n      iex> use Witchcraft\n      ...>\n      ...> 0\n      ...> |> new([\"logs\"])\n      ...> |> monad do\n      ...>   tell [\"Start\"]\n      ...>   tell [\"BANG!\"]\n      ...>   tell [\"shhhhhhh...\"]\n      ...>   tell [\"LOUD NOISES!!!\"]\n      ...>   tell [\"End\"]\n      ...>\n      ...>   return 42\n      ...> end\n      ...> |> censor(&Enum.reject(&1, fn log -> String.upcase(log) == log end))\n      ...> |> run()\n      {42, [\"Start\", \"shhhhhhh...\", \"End\"]}\n\n  \"\"\"\n  @spec censor(Writer.t(), (any() -> any())) :: Writer.t()\n  def censor(writer, fun) do\n    pass(monad writer do\n      value <- writer\n      return {value, fun}\n    end)\n  end\nend\n"
  },
  {
    "path": "lib/algae.ex",
    "content": "defmodule Algae do\n  @moduledoc \"\"\"\n  Builder DSL to handle common ADT definition use cases\n  \"\"\"\n\n  import Algae.Internal\n\n  @type ast() :: {atom(), any(), any()}\n\n  @doc ~S\"\"\"\n  Build a product type\n\n  Includes:\n\n  * Struct\n  * Type definition\n  * Constructor function (for piping and defaults)\n  * Implicit defaults for simple values\n\n  ## Definition\n\n  For convenveniece, several variants of the DSL are available.\n\n  ### Standard\n\n      defmodule Player do\n        # =============== #\n        # Data Definition #\n        # =============== #\n\n        defdata do\n          name       :: String.t()\n          hit_points :: non_neg_integer()\n          experience :: non_neg_integer()\n        end\n\n        # =================== #\n        #    Rest of Module   #\n        # (business as usual) #\n        # =================== #\n\n        @spec attack(t(), t()) :: {t(), t()}\n        def attack(%{experience: xp} = player, %{hit_points: hp} = target) do\n          {\n            %{player | experience: xp + 50},\n            %{target | hit_points: hp - 10}\n          }\n        end\n      end\n\n      #=> %Player{name: \"Sir Bob\", hit_points: 10, experience: 500}\n\n  ### Single Field Shorthand\n\n  Without any fields specified, Algae will default to a single field with\n  the same name as the module (essentially a \"wrapper type\"). You must still\n  provide the type for this field, however.\n\n  Embedded in another module:\n\n      defmodule Id do\n        defdata any()\n      end\n\n      %Id{}\n      #=> %Id{id: nil}\n\n  Standalone:\n\n      defdata Wrapper :: any()\n\n      %Wrapper{}\n      #=> %Wrapper{wrapper: nil}\n\n  ## Constructor\n\n  A helper function, especially useful for piping. The order of arguments is\n  the same as the order that they are defined in.\n\n      defmodule Person do\n        defdata do\n          name :: String.t()\n          age  :: non_neg_integer()\n        end\n      end\n\n      Person.new(\"Rachel Weintraub\")\n      #=> %Person{\n      #     name: \"Rachel Weintraub\",\n      #     age:  0\n      #   }\n\n  ### Constructor Defaults\n\n  Fields will automatically default to a sensible value (a typical \"zero\" for\n  that datatype). For example, `non_neg_integer()` will default to `0`,\n  and `String.t()` will default to `\"\"`.\n\n  You may also overwrite these defaults with the `\\\\\\\\` syntax.\n\n      defmodule Pet do\n        defdata do\n          name      :: String.t()\n          leg_count :: non_neg_integer() \\\\\\\\ 4\n        end\n      end\n\n      Pet.new(\"Crookshanks\")\n      #=> %Pet{\n      #     name: \"Crookshanks\",\n      #     leg_count: 4\n      #   }\n\n      Pet.new(\"Paul the Psychic Octopus\", 8)\n      #=> %Pet{\n      #     name: \"Paul the Psychic Octopus\",\n      #     leg_count: 8\n      #   }\n\n  This overwriting syntax is _required_ for complex types:\n\n      defdata Grocery do\n        item :: {String.t(), integer(), boolean()} \\\\\\\\ {\"Apple\", 4, false}\n      end\n\n      Grocery.new()\n      #=> %Grocery{\n      #     item: {\"Apple\", 4, false}\n      #   }\n\n  ### Overwrite Constructor\n\n  The `new` constructor function may be overwritten.\n\n      iex> defmodule Constant do\n      ...>   defdata fun()\n      ...>\n      ...>   def new(value), do: %Constant{constant: fn _ -> value end}\n      ...> end\n      ...>\n      ...> fourty_two = Constant.new(42)\n      ...> fourty_two.constant.(33)\n      42\n\n  ## Empty Tag\n\n  An empty type (with no fields) is definable using the `none`() type\n\n      defmodule Nothing do\n        defdata none()\n      end\n\n      Nothing.new()\n      #=> %Nothing{}\n\n  \"\"\"\n  defmacro defdata(ast) do\n    caller_module = __CALLER__.module\n\n    case ast do\n      {:none, _, _} = type ->\n        embedded_data_ast()\n\n      {:\\\\, _, [{:::, _, [module_ctx, type]}, default]} ->\n        caller_module\n        |> modules(module_ctx)\n        |> data_ast(default, type)\n\n      {:\\\\, _, [type, default]} ->\n        caller_module\n        |> List.wrap()\n        |> embedded_data_ast(default, type)\n\n      {:::, _, [module_ctx, {:none, _, _} = type]} ->\n        caller_module\n        |> modules(module_ctx)\n        |> data_ast(type)\n\n      {:::, _, [module_ctx, type]} ->\n        caller_module\n        |> modules(module_ctx)\n        |> data_ast(default_value(type), type)\n\n      {_, _, _} = type ->\n        data_ast(caller_module, type)\n\n      [do: {:__block__, _, lines}] ->\n        data_ast(lines, __CALLER__)\n\n      [do: line] ->\n        data_ast([line], __CALLER__)\n    end\n  end\n\n  defmacro defdata(module_ctx, do: body) do\n    module_name =\n      __CALLER__.module\n      |> modules(module_ctx)\n      |> Module.concat()\n\n    inner =\n      body\n      |> case do\n           {:__block__, _, lines} -> lines\n           line -> List.wrap(line)\n      end\n      |> data_ast(__CALLER__)\n\n    quote do\n      defmodule unquote(module_name) do\n        unquote(inner)\n      end\n    end\n  end\n\n  @doc \"\"\"\n  Build a sum (coproduct) type from product types\n\n      defmodule Light do\n        # ============== #\n        # Sum Definition #\n        # ============== #\n\n        defsum do\n          defdata Red    :: none()\n          defdata Yellow :: none()\n          defdata Green  :: none()\n        end\n\n        # =================== #\n        #    Rest of Module   #\n        # (business as usual) #\n        # =================== #\n\n        def from_number(1), do: %Light.Red{}\n        def from_number(2), do: %Light.Yellow{}\n        def from_number(3), do: %Light.Green{}\n      end\n\n      Light.new()\n      #=> %Light.Red{}\n\n  ## Embedded Products\n\n  Data with multiple fileds can be defined directly as part of a sum\n\n      defmodule Pet do\n        defsum do\n          defdata Cat do\n            name :: String.t()\n            claw_sharpness :: String.t()\n          end\n\n          defdata Dog do\n            name :: String.t()\n            bark_loudness :: non_neg_integer()\n          end\n        end\n      end\n\n  ## Default Constructor\n\n  The first `defdata`'s constructor will be the default constructor for the sum\n\n      defmodule Maybe do\n        defsum do\n          defdata Nothing :: none()\n          defdata Just    :: any()\n        end\n      end\n\n      Maybe.new()\n      #=> %Maybe.Nothing{}\n\n  ## Tagged Unions\n\n  Sums join existing types with tags: new types to help distibguish the context\n  that they are in (the sum type)\n\n      defdata Book  :: String.t() \\\\\\\\ \"War and Peace\"\n      defdata Video :: String.t() \\\\\\\\ \"2001: A Space Odyssey\"\n\n      defmodule Media do\n        defsum do\n          defdata Paper :: Book.t()\n          defdata Film  :: Video.t() \\\\\\\\ Video.new(\"A Clockwork Orange\")\n        end\n      end\n\n      media = Media.new()\n      #=> %Paper{\n      #      paper: %Book{\n      #        book: \"War and Peace\"\n      #      }\n      #   }\n\n  \"\"\"\n  @spec defsum([do: {:__block__, [any()], ast()}]) :: ast()\n  defmacro defsum(do: {:__block__, _, [first | _] = parts} = block) do\n    module_ctx = __CALLER__.module\n    types = or_types(parts, module_ctx)\n\n    default_module =\n      module_ctx\n      |> List.wrap()\n      |> Kernel.++(submodule_name(first))\n      |> Module.concat()\n\n    quote do\n      @type t :: unquote(types)\n      unquote(block)\n\n      @spec new() :: t()\n      def new, do: unquote(default_module).new()\n\n      defoverridable [new: 0]\n    end\n  end\nend\n"
  },
  {
    "path": "mix.exs",
    "content": "defmodule Algae.Mixfile do\n  use Mix.Project\n\n  def project do\n    [\n      app: :algae,\n      aliases: aliases(),\n      deps: deps(),\n      preferred_cli_env: [quality: :test],\n\n      # Versions\n      version: \"1.3.1\",\n      elixir: \"~> 1.9\",\n      elixirc_paths: elixirc_paths(Mix.env()),\n\n      # Docs\n      name: \"Algae\",\n      docs: docs(),\n\n      # Hex\n      description: \"Bootstrapped algebraic data types for Elixir\",\n      package: package()\n    ]\n  end\n\n  defp aliases do\n    [\n      quality: [\n          \"test\",\n          \"credo --strict\"\n        ]\n    ]\n  end\n\n  defp elixirc_paths(:test), do: [\"lib\", \"test/support\"]\n  defp elixirc_paths(_), do: [\"lib\"]\n\n  defp deps do\n    [\n      {:credo,       \"~> 1.5\",  only: [:dev, :test],        runtime: false},\n      {:inch_ex,     \"~> 2.0\",  only: [:dev, :docs, :test], runtime: false},\n      {:dialyxir,    \"~> 1.1\",  only: :dev,                 runtime: false},\n      {:earmark,     \"~> 1.4\",  only: :dev,                 runtime: false},\n      {:ex_doc,      \"~> 0.23\", only: :dev,                 runtime: false},\n\n      {:quark,       \"~> 2.2\"},\n      {:type_class,  \"~> 1.2\"},\n      {:witchcraft,  \"~> 1.0\"},\n    ]\n  end\n\n  defp docs do\n    [\n      extras: [\"README.md\"],\n      logo: \"./brand/mini-logo.png\",\n      main: \"readme\",\n      source_url: \"https://github.com/witchcrafters/algae\"\n    ]\n  end\n\n  defp package do\n    [\n      licenses: [\"Apache-2.0\"],\n      links: %{\"GitHub\" => \"https://github.com/witchcrafters/algae\"},\n      maintainers: [\"Brooklyn Zelenka\", \"Steven Vandevelde\"]\n    ]\n  end\nend\n"
  },
  {
    "path": "shell.nix",
    "content": "let\n  nixpkgs = import (fetchTarball {\n    # Run `cachix use jechol` to use compiled binary cache.\n    url = \"https://github.com/jechol/nixpkgs/archive/21.11-otp24-no-jit.tar.gz\";\n    sha256 = \"sha256:1lka707hrnkp70vny99m9fmp4a8136vl7addmpfsdvkwb81d1jk9\";\n  }) { };\n  platform = if nixpkgs.stdenv.isDarwin then [\n    nixpkgs.darwin.apple_sdk.frameworks.CoreServices\n    nixpkgs.darwin.apple_sdk.frameworks.Foundation\n  ] else if nixpkgs.stdenv.isLinux then\n    [ nixpkgs.inotify-tools ]\n  else\n    [ ];\nin nixpkgs.mkShell {\n  buildInputs = with nixpkgs;\n    [\n      # OTP\n      erlang\n      elixir\n    ] ++ platform;\n}\n"
  },
  {
    "path": "test/algae_dsl_aliasing_test.exs",
    "content": "defmodule AlgaeDslAliasingTest.Base do\n  import Algae\n\n  alias __MODULE__\n\n  defmodule A do\n    defdata do\n      a :: String.t()\n    end\n  end\n\n  defmodule B do\n    defdata do\n      b :: Base.A.t() \\\\ Base.A.new(\"a for amazing!\")\n    end\n  end\n\n  defmodule C do\n    defdata do\n      c :: Base.B.t()\n    end\n  end\nend\n"
  },
  {
    "path": "test/algae_test.exs",
    "content": "defmodule AlgaeTest do\n  alias Example.{Animal, Book, Media, Wrapper}\n  use ExUnit.Case\n\n  doctest Algae, import: true\n  doctest Algae.Id, import: true\n\n  doctest Algae.Maybe,  import: true\n  doctest Algae.Either, import: true\n\n  doctest Algae.Free, import: true\n\n  doctest Algae.Tree.BinarySearch, import: true\n  doctest Algae.Tree.Rose,         import: true\n\n  doctest Algae.Reader, import: true\n  doctest Algae.Writer, import: true\n  doctest Algae.State,  import: true\n\n  test \"constructor for empty type\" do\n    assert Example.Light.new() == %Example.Light.Red{}\n  end\n\n  test \"constructor with one field\" do\n    assert %Example.Wrapper{} == %Wrapper{wrapper: nil}\n  end\n\n  test \"constructor with multiple fields uses defaults\" do\n    crookshanks =\n      %Animal{\n        name: \"Crookshanks\",\n        leg_count: 4\n      }\n\n    assert Animal.new(\"Crookshanks\") == crookshanks\n  end\n\n  test \"constructor with multiple fields can overwrite all fields\" do\n    paul =\n      %Animal{\n        name: \"Paul the Psychic Octopus\",\n        leg_count: 8\n      }\n\n    assert Animal.new(\"Paul the Psychic Octopus\", 8) == paul\n  end\n\n  test \"sum constructor uses the first tagged type\" do\n    paper =\n      %Media.Paper{\n        paper: %Book{\n          book: \"War and Peace\"\n        }\n      }\n\n    assert Media.new() == paper\n  end\n\n  test \"test either keeps left state using convey\" do\n    use Witchcraft\n\n    r_val = Algae.Either.Right.new(\"right!\")\n    r_fun = Algae.Either.Right.new(fn x -> \"who's there? \" <> x end)\n    l_val = Algae.Either.Left.new(\"left the building!!!\")\n\n    assert convey(r_val, r_fun) == Algae.Either.Right.new(\"who's there? right!\")\n    assert convey(l_val, r_fun) == l_val\n    assert convey(l_val, l_val) == l_val\n    assert convey(r_val, l_val) == l_val\n  end\n\nend\n"
  },
  {
    "path": "test/support/example.ex",
    "content": "import Algae\n\ndefmodule Example do\n  @moduledoc false\n\n  defdata Complex :: ([{:ok, integer()}] | number()) \\\\ 22\n\n  defdata Any  :: any()\n  defdata Int  :: integer()\n  defdata None :: none()\n\n  defmodule Embedded.One do\n    @moduledoc false\n\n    defdata do: quux :: any() \\\\ 22\n  end\n\n  defmodule Embedded.Many do\n    @moduledoc false\n\n    defdata do\n      first  :: any()\n      second :: integer() \\\\ 42\n    end\n  end\n\n  defdata Bare do\n    first  :: any()\n    second :: non_neg_integer() \\\\ 22\n    third  :: any()\n  end\n\n  defmodule Simple do\n    @moduledoc false\n\n    defdata any()\n  end\n\n  defmodule Sum.Lights do\n    @moduledoc false\n\n    defsum do\n      defdata Red    :: any() \\\\ 22\n      defdata Yellow :: any()\n      defdata Green  :: none()\n    end\n  end\n\n  defmodule Sum.Maybe do\n    @moduledoc false\n\n    defsum do\n      defdata Just do\n        value :: any()\n      end\n\n      defdata Nada :: none()\n    end\n  end\n\n  defmodule Player do\n    @moduledoc false\n\n    # =============== #\n    # Data Definition #\n    # =============== #\n\n    defdata do\n      name       :: String.t()\n      hit_points :: non_neg_integer()\n      experience :: non_neg_integer()\n    end\n\n    # =================== #\n    #    Rest of Module   #\n    # (business as usual) #\n    # =================== #\n\n    @spec attack(t(), t()) :: {t(), t()}\n    def attack(player = %{experience: xp}, target = %{hit_points: hp}) do\n      {\n        %{player | experience: xp + 50},\n        %{target | hit_points: hp - 10}\n      }\n    end\n  end\n\n  defmodule Id do\n    @moduledoc false\n\n    defdata any()\n  end\n\n  defdata Wrapper :: any()\n\n  defmodule Person do\n    @moduledoc false\n\n    defdata do\n      name :: String.t()\n      age  :: non_neg_integer()\n    end\n  end\n\n  defmodule Animal do\n    @moduledoc false\n\n    defdata do\n      name      :: String.t()\n      leg_count :: non_neg_integer() \\\\ 4\n    end\n  end\n\n  defdata Grocery do\n    item :: {String.t(), integer(), boolean()} \\\\ {\"Apple\", 4, false}\n  end\n\n  defmodule Constant do\n    @moduledoc false\n\n    defdata fun()\n\n    def new(value), do: %Constant{constant: fn _ -> value end}\n  end\n\n  defmodule Nothing do\n    @moduledoc false\n\n    defdata none()\n  end\n\n  defmodule Light do\n    @moduledoc false\n\n    # ============== #\n    # Sum Definition #\n    # ============== #\n\n    defsum do\n      defdata Red    :: none()\n      defdata Yellow :: none()\n      defdata Green  :: none()\n    end\n\n    # =================== #\n    #    Rest of Module   #\n    # (business as usual) #\n    # =================== #\n\n    def from_number(1), do: %Light.Red{}\n    def from_number(2), do: %Light.Yellow{}\n    def from_number(3), do: %Light.Green{}\n  end\n\n  defmodule Pet do\n    @moduledoc false\n\n    defsum do\n      defdata Cat do\n        name :: String.t()\n        claw_sharpness :: String.t()\n      end\n\n      defdata Dog do\n        name :: String.t()\n        bark_loudness :: non_neg_integer()\n      end\n    end\n  end\n\n  defmodule Option do\n    @moduledoc false\n\n    defsum do\n      defdata None :: none()\n      defdata Some :: any()\n    end\n  end\n\n  defdata Book  :: String.t() \\\\ \"War and Peace\"\n  defdata Video :: String.t() \\\\ \"2001: A Space Odyssey\"\n\n  defmodule Media do\n    @moduledoc false\n\n    defsum do\n      defdata Paper :: Example.Book.t()  \\\\ Example.Book.new()\n      defdata Film  :: Example.Video.t() \\\\ Example.Video.new(\"A Clockwork Orange\")\n    end\n  end\nend\n"
  },
  {
    "path": "test/test_helper.exs",
    "content": "ExUnit.start()\n"
  }
]