[
  {
    "path": ".gitignore",
    "content": "# added by GitSavvy\n/elm-stuff/\n\n# added by GitSavvy\nnode_modules\n\n# added by GitSavvy\n/documentation.json\n\n# added by GitSavvy\n/monocle.js\n\n# added by GitSavvy\n/documentation.md\n\n/package-lock.json\n\n/yarn-error.log\n\n/yarn.lock\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\nCopyright (c) 2016 Artur Opala\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
  },
  {
    "path": "README.md",
    "content": "[![Build Status](https://semaphoreci.com/api/v1/arturopala/elm-monocle/branches/master/badge.svg)](https://semaphoreci.com/arturopala/elm-monocle)\n\nelm-monocle\n===========\n\nA [Monocle](http://optics-dev.github.io/Monocle/)-inspired library providing purely functional abstractions to manipulate complex records in the [elm](http://www.elm-lang.org/) language.\n\nPublished as [**arturopala/elm-monocle**](http://package.elm-lang.org/packages/arturopala/elm-monocle/latest) library.\n\n\n# Long Example\n\n```elm\nimport Monocle.Optional exposing (Optional)\nimport Monocle.Lens exposing (Lens)\n\n\ntype StreetType\n    = Street\n    | Avenue\n\n\ntype Country\n    = US\n    | UK\n    | FI\n    | PL\n    | DE\n\n\ntype alias Address =\n    { streetName : String\n    , streetType : StreetType\n    , floor : Maybe Int\n    , town : String\n    , region : Maybe String\n    , postcode : String\n    , country : Country\n    }\n\n\ntype alias Place =\n    { name : String\n    , description : Maybe String\n    , address : Maybe Address\n    }\n\n\naddressOfPlace : Optional Place Address\naddressOfPlace =\n    Optional .address (\\b a -> { a | address = Just b })\n\n\nregionOfAddress : Optional Address String\nregionOfAddress =\n    Optional .region (\\b a -> { a | region = Just b })\n\n\nstreetNameOfAddress : Lens Address String\nstreetNameOfAddress =\n    Lens .streetName (\\b a -> { a | streetName = b })\n\n\nregionOfPlace : Optional Place String\nregionOfPlace =\n    addressOfPlace |> Monocle.Compose.optionalWithOptional regionOfAddress\n\n\nstreetNameOfPlace : Optional Place String\nstreetNameOfPlace =\n    addressOfPlace |> Monocle.Compose.optionalWithLens streetNameOfAddress\n\n\nplace : Place\nplace =\n    { name = \"MyPlace\"\n    , description = Nothing\n    , address =\n        Just\n            { streetName = \"Union Road\"\n            , streetType = Street\n            , floor = Nothing\n            , town = \"Daisytown\"\n            , region = Nothing\n            , postcode = \"00100\"\n            , country = US\n            }\n    }\n\n\nupdatedPlace : Place\nupdatedPlace =\n    place\n        |> regionOfPlace.set \"NorthEast\"\n        |> streetNameOfPlace.set \"Union Avenue\"\n```\n\n# Abstractions\n\n## Iso\n\nAn Iso is a tool which converts elements of type A into elements of type B and back without loss.\n\n```elm\n    type alias Iso a b =\n        { get : a -> b\n        , reverseGet : b -> a\n        }\n```\n\n###### Example\n\n```elm\n    string2CharListIso : Iso String (List Char)\n    string2CharListIso =\n        Iso String.toList String.fromList\n\n    (string2CharListIso.get \"ABcdE\") == ['A','B','c','d','E']\n    (string2CharListIso.reverseGet ['A','B','c','d','E']) == \"ABcdE\"\n```\n\n## Prism\n\nA Prism is a tool which optionally converts elements of type A into elements of type B and back.\n\n```elm\n    type alias Prism a b =\n        { getOption : a -> Maybe b\n        , reverseGet : b -> a\n        }\n```\n\n###### Example\n\n```elm\n    string2IntPrism : Prism String Int\n    string2IntPrism =\n        Prism String.toInt String.fromInt\n\n    string2IntPrism.getOption \"17896\" == Just 17896\n    string2IntPrism.getOption \"1a896\" == Nothing\n    string2IntPrism.reverseGet 1626767 = \"1626767\"\n```\n\n## Lens\n\nA Lens is a functional concept which solves a very common problem: how to easily update a complex immutable structure, for this purpose Lens acts as a zoom into a record. \n\n```elm\n    type alias Lens a b =\n        { get : a -> b\n        , set : b -> a -> a\n        }\n```\n\n###### Example\n\n```elm\n    type alias Address = \n        { streetName: String\n        , postcode: String\n        , town: String\n        }\n\n    type alias Place =\n        { name: String\n        , address: Address\n        }\n\n    addressStreetNameLens : Lens Address String\n    addressStreetNameLens =\n        Lens .streetName (\\b a -> { a | streetName = b })\n\n    placeAddressLens : Lens Place Address\n    placeAddressLens =\n        Lens .address (\\b a -> { a | address = b })\n\n    placeStreetName: Lens Place String\n    placeStreetName =\n        placeAddressLens |> Monocle.Compose.lensWithLens addressStreetNameLens\n\n    myPlace = Place \"my\" (Address \"Elm\" \"00001\" \"Daisytown\")\n    placeStreetName.get myPlace == \"Elm\"\n    \n    myNewPlace = placeStreetName.set \"Oak\" myPlace\n\n    placeStreetName.get myNewPlace == \"Oak\"\n    myNewPlace == Place \"my\" (Address \"Oak\" \"00001\" \"Daisytown\")\n\n```\n\n## Optional\n\nA Optional is a weaker Lens and a weaker Prism.\n\n```elm\n    type alias Optional a b =\n        { getOption : a -> Maybe b\n        , set : b -> a -> a\n        }\n```\n\n###### Example\n\n```elm\n    addressRegionOptional : Optional Address String\n    addressRegionOptional =\n        Optional .region (\\b a -> { a | region = Just b })\n\n    string2IntPrism : Prism String Int\n    string2IntPrism = Prism String.toInt String.fromInt\n\n    addressRegionIntOptional: Optional Address Int\n    addressRegionIntOptional =\n        addressRegionOptional |> Monocle.Compose.optionalWithPrism string2IntPrism\n\n    string2CharListIso : Iso String (List Char)\n    string2CharListIso = Iso String.toList String.fromList\n\n    addressRegionListCharOptional: Optional Address (List Char)\n    addressRegionListCharOptional =\n        addressRegionOptional |> Monocle.Compose.optionalWithIso string2CharListIso\n\n    modifyRegion: String -> String\n    modifyRegion region = String.reverse region\n\n    modifyAddressRegion: Address -> Maybe Address\n    modifyAddressRegion address = Optional.modifyOption addressRegionOptional modifyRegion address\n\n    modifyRegion: String -> String\n    modifyRegion region = String.reverse region\n\n    modifyAddressRegion: Address -> Address\n    modifyAddressRegion address = Optional.modify addressRegionOptional modifyRegion address\n```\n\n## Traversal\n\nA Traversal allows you to modify many elements at once.\n\n```elm\n    type alias Traversal a b =\n        (b -> b) -> a -> a\n```\n\n(`Traversal a b` is just an alias for a function that applies\na transformation over `b` elements of a larger `a` structure.)\n\n###### Example\n\n```elm\n    firstNameLens : Lens Friend String\n    firstNameLens =\n        Lens .firstName (\\b a -> { a | firstName = b })\n\n    bestFriendsTraversal : Traversal (List Friend) Friend\n    bestFriendsTraversal =\n        Traversal.some\n            Traversal.list\n            (\\friend -> friend.value == Best)\n\n    friendsLens : Lens Account (List Friend)\n    friendsLens =\n        Lens .friends (\\b a -> { a | friends = b })\n\n    firstNamesOfBestFriends : Traversal Account String\n    firstNamesOfBestFriends =\n        friendsLens\n            |> Compose.lensWithTraversal bestFriendsTraversal\n            |> Compose.traversalWithLens firstNameLens\n\n    upcaseBestFriendsFirstNames : Account -> Account\n    upcaseBestFriendsFirstNames account =\n        Traversal.modify firstNamesOfBestFriends String.toUpper\n```\n\n## Common\nCommon lenses/prisms/optionals that most projects will use.\n\n####  Step into a `Maybe` value.\n```elm\n    maybe.set 5 Nothing\n    > Just 5\n```\n####  Step into an `Array` at the given index.\n```elm\n    .getOption (array 2) (Array.fromList [ 10, 11, 12, 13 ])\n    > Just 12\n\n    .getOption (array 8) (Array.fromList [ 10, 11, 12, 13 ])\n    > Nothing\n```\n####  Step into a `Dict` with the given key.\n```elm\n    .getOption (dict \"Tom\") (Dict.fromList [ ( \"Tom\", \"Cat\" ) ])\n    > Just \"Cat\"\n\n    .getOption (dict \"Jerry\") (Dict.fromList [ ( \"Tom\", \"Cat\" ) ])\n    > Nothing\n```\n####  Step into the success value of a `Result`.\n```elm    \n    result.getOption (Ok 5)\n    > Just 5\n\n    result.getOption (Err \"500\")\n    > Nothing\n```\n####  Step into a record with an `id` key.\nSince records with an `id` field are incredible common, this is\nincluded for convenience. It also serves as a simple recipe for\ncreating record lenses.\n```elm   \n    id.get { id = 1000, name = ... }\n    > 1000\n```\n####  Step into the first element of a pair.\n```elm\n    first.get ( 'a', 'b' )\n    > 'a'\n```\n####  Step into the second element of a pair.\n```elm    \n    second.get ( 'a', 'b' )\n    > 'b'\n```\n\n# Build\n\n## Prerequisites\n\n-   Node.js\n-   Yarn\n-   Run `yarn install-with-elm`\n\n## Compile\n\nRun `yarn compile`\n\n## Test\n\nRun `elm-test`\n"
  },
  {
    "path": "elm.json",
    "content": "{\n    \"type\": \"package\",\n    \"name\": \"arturopala/elm-monocle\",\n    \"summary\": \"Library providing functional tools to manipulate complex records\",\n    \"license\": \"MIT\",\n    \"version\": \"2.2.0\",\n    \"exposed-modules\": [\n        \"Monocle.Iso\",\n        \"Monocle.Prism\",\n        \"Monocle.Lens\",\n        \"Monocle.Optional\",\n        \"Monocle.Traversal\",\n        \"Monocle.Common\",\n        \"Monocle.Compose\"\n    ],\n    \"elm-version\": \"0.19.0 <= v < 0.20.0\",\n    \"dependencies\": {\n        \"elm/core\": \"1.0.0 <= v < 2.0.0\"\n    },\n    \"test-dependencies\": {\n        \"elm-explorations/test\": \"1.1.0 <= v < 1.1.1\"\n    }\n}\n"
  },
  {
    "path": "example/OptionalExample.elm",
    "content": "module OptionalExample exposing (Address, Country(..), Place, StreetType(..), addressOfPlace, place, regionOfAddress, regionOfPlace, streetNameOfAddress, streetNameOfPlace, updatedPlace)\n\nimport Monocle.Lens exposing (Lens)\nimport Monocle.Optional exposing (Optional)\n\n\ntype StreetType\n    = Street\n    | Avenue\n\n\ntype Country\n    = US\n    | UK\n    | FI\n    | PL\n    | DE\n\n\ntype alias Address =\n    { streetName : String\n    , streetType : StreetType\n    , floor : Maybe Int\n    , town : String\n    , region : Maybe String\n    , postcode : String\n    , country : Country\n    }\n\n\ntype alias Place =\n    { name : String\n    , description : Maybe String\n    , address : Maybe Address\n    }\n\n\naddressOfPlace : Optional Place Address\naddressOfPlace =\n    let\n        getOption p =\n            p.address\n\n        set a p =\n            { p | address = Just a }\n    in\n    Optional getOption set\n\n\nregionOfAddress : Optional Address String\nregionOfAddress =\n    let\n        getOption a =\n            a.region\n\n        set r a =\n            { a | region = Just r }\n    in\n    Optional getOption set\n\n\nstreetNameOfAddress : Lens Address String\nstreetNameOfAddress =\n    let\n        get a =\n            a.streetName\n\n        set sn a =\n            { a | streetName = sn }\n    in\n    Lens get set\n\n\nregionOfPlace : Optional Place String\nregionOfPlace =\n    Monocle.Optional.compose addressOfPlace regionOfAddress\n\n\nstreetNameOfPlace : Optional Place String\nstreetNameOfPlace =\n    Monocle.Optional.composeLens addressOfPlace streetNameOfAddress\n\n\nplace : Place\nplace =\n    { name = \"MyPlace\"\n    , description = Nothing\n    , address =\n        Just\n            { streetName = \"Union Road\"\n            , streetType = Street\n            , floor = Nothing\n            , town = \"Daisytown\"\n            , region = Nothing\n            , postcode = \"00100\"\n            , country = US\n            }\n    }\n\n\nupdatedPlace : Place\nupdatedPlace =\n    place |> regionOfPlace.set \"NorthEast\" |> streetNameOfPlace.set \"Union Avenue\"\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"elm-monocle\",\n  \"version\": \"1.6.0\",\n  \"description\": \"Library providing purely functional abstractions to manipulate records\",\n  \"scripts\": {\n    \"compile\": \"elm make ./src/**/*.elm --output monocle.js\",\n    \"install-with-elm\": \"yarn install && elm make\",\n    \"test\": \"elm-test\",\n    \"test-and-watch\": \"elm-test --watch\",\n    \"bump\": \"elm bump\",\n    \"publish\": \"elm publish\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/arturopala/elm-monocle.git\"\n  },\n  \"keywords\": [\n    \"monocle\",\n    \"lens\",\n    \"iso\",\n    \"prism\",\n    \"optional\",\n    \"record\"\n  ],\n  \"author\": \"Artur Opala\",\n  \"license\": \"MIT\",\n  \"bugs\": {\n    \"url\": \"https://github.com/arturopala/elm-monocle/issues\"\n  },\n  \"homepage\": \"https://github.com/arturopala/elm-monocle#readme\",\n  \"devDependencies\": {\n    \"elm\": \"^0.19.0\",\n    \"elm-test\": \"0.19.0-beta9\"\n  }\n}\n"
  },
  {
    "path": "src/Monocle/Common.elm",
    "content": "module Monocle.Common exposing\n    ( maybe\n    , array\n    , list\n    , listToArray\n    , dict\n    , result\n    , id\n    , first\n    , second\n    )\n\n{-| Common lenses/prisms/optionals that most projects will use.\n\n@docs maybe\n@docs array\n@docs list\n@docs listToArray\n@docs dict\n@docs result\n@docs id\n@docs first\n@docs second\n\n-}\n\nimport Array exposing (Array)\nimport Dict exposing (Dict)\nimport Monocle.Iso exposing (Iso)\nimport Monocle.Lens as Lens exposing (Lens)\nimport Monocle.Optional as Optional exposing (Optional)\n\n\n{-| Step into a `Maybe` value.\n\n    maybe.set 5 Nothing\n        > Just 5\n\n-}\nmaybe : Optional (Maybe a) a\nmaybe =\n    { getOption = identity\n    , set = always << Just\n    }\n\n\n{-| Step into an `Array` at the given index.\n\n    .getOption (array 2) (Array.fromList [ 10, 11, 12, 13 ])\n        > Just 12\n\n    .getOption (array 8) (Array.fromList [ 10, 11, 12, 13 ])\n        > Nothing\n\n-}\narray : Int -> Optional (Array a) a\narray index =\n    { getOption = Array.get index\n    , set = Array.set index\n    }\n\n\n{-| Step into an `List` at the given index.\n(shortcut to avoid converting a `List` to an `Array` ; if it is too slow,\nconsider using `array` and an `Array` instead of a `List` in your data)\n\n    .getOption (list 2) [ 10, 11, 12, 13 ]\n        > Just 12\n\n    .getOption (list 8) [ 10, 11, 12, 13 ]\n        > Nothing\n\n-}\nlist : Int -> Optional (List a) a\nlist index =\n    Optional.compose (Optional.fromLens (Lens.fromIso listToArray)) (array index)\n\n\n{-| Iso that converts a list to an array.\n\n    .get listToArray [ 1, 2, 3, 4 ]\n        == Array.fromList [ 1, 2, 3, 4 ]\n        > True\n\n    .reverseGet listToArray (Array.fromList [ 9, 8, 7, 6 ])\n        == [ 9, 8, 7, 6 ]\n        > True\n\n-}\nlistToArray : Iso (List a) (Array a)\nlistToArray =\n    Iso Array.fromList Array.toList\n\n\n{-| Step into a `Dict` with the given key.\n\n    .getOption (dict \"Tom\") (Dict.fromList [ ( \"Tom\", \"Cat\" ) ])\n        > Just \"Cat\"\n\n    .getOption (dict \"Jerry\") (Dict.fromList [ ( \"Tom\", \"Cat\" ) ])\n        > Nothing\n\n-}\ndict : comparable -> Optional (Dict comparable v) v\ndict key =\n    { getOption = Dict.get key\n    , set = Dict.insert key\n    }\n\n\n{-| Step into the success value of a `Result`.\n\n    result.getOption (Ok 5)\n        > Just 5\n\n    result.getOption (Err \"500\")\n        > Nothing\n\n-}\nresult : Optional (Result e a) a\nresult =\n    { getOption = Result.toMaybe\n    , set = always << Ok\n    }\n\n\n{-| Step into a record with an `id` key.\n\n    id.get { id = 1000, name = ... }\n    > 1000\n\nSince records with an `id` field are incredible common, this is\nincluded for convenience. It also serves as a simple recipe for\ncreating record lenses.\n\n-}\nid : Lens { a | id : b } b\nid =\n    { get = .id\n    , set = \\a record -> { record | id = a }\n    }\n\n\n{-| Step into the first element of a pair.\n\n    first.get ( 'a', 'b' )\n        > 'a'\n\n-}\nfirst : Lens ( a, b ) a\nfirst =\n    { get = Tuple.first\n    , set = \\a ( _, b ) -> ( a, b )\n    }\n\n\n{-| Step into the second element of a pair.\n\n    second.get ( 'a', 'b' )\n        > 'b'\n\n-}\nsecond : Lens ( a, b ) b\nsecond =\n    { get = Tuple.second\n    , set = \\b ( a, _ ) -> ( a, b )\n    }\n"
  },
  {
    "path": "src/Monocle/Compose.elm",
    "content": "module Monocle.Compose exposing\n    ( isoWithIso, isoWithPrism, isoWithLens, isoWithOptional, isoWithTraversal\n    , prismWithIso, prismWithPrism, prismWithLens, prismWithOptional, prismWithTraversal\n    , lensWithIso, lensWithPrism, lensWithLens, lensWithOptional, lensWithTraversal\n    , optionalWithIso, optionalWithPrism, optionalWithLens, optionalWithOptional, optionalWithTraversal\n    , traversalWithIso, traversalWithPrism, traversalWithLens, traversalWithOptional, traversalWithTraversal\n    )\n\n{-| Pipeline-friendly composition helpers\n\nUsing these allow to compose an \"outer\" optic with an \"inner\" other optic.\n\nOptics in functional programming languages that support typeclasses can be\nexpressed as functions that compose through the composition operator (just like\nany other functions) ; in Elm (plus typeclasses), it would look like this:\n\n    lensAtoB >> lensBtoC >> lensCtoD == lensAtoD\n\n    lensAtoB >> optionalBtoC >> prismCtoD == optionalAtoC\n\nBut Elm doesn't support typeclasses, so we're stuck with defining composition\nfunctions that look similar like this:\n\n    import Monocle.Compose as Compose\n    lensAtoB\n      |> Compose.lensWithLens lensBtoC\n      |> Compose.lensWithLens lensCtoD\n      == lensAtoD\n    lensAtoB\n      |> Compose.lensWithOptional optionalBtoC\n      |> Compose.optionalWithPrism prismCtoD\n      == optionalAtoC\n\nThis is arguably more \"discoverable\" and maybe more readable, if more verbose.\n\n\n# From an Iso\n\n@docs isoWithIso, isoWithPrism, isoWithLens, isoWithOptional, isoWithTraversal\n\n\n# From a Prism\n\n@docs prismWithIso, prismWithPrism, prismWithLens, prismWithOptional, prismWithTraversal\n\n\n# From a Lens\n\n@docs lensWithIso, lensWithPrism, lensWithLens, lensWithOptional, lensWithTraversal\n\n\n# From an Optional\n\n@docs optionalWithIso, optionalWithPrism, optionalWithLens, optionalWithOptional, optionalWithTraversal\n\n\n# From a Traversal\n\n@docs traversalWithIso, traversalWithPrism, traversalWithLens, traversalWithOptional, traversalWithTraversal\n\n-}\n\nimport Monocle.Iso as Iso exposing (Iso)\nimport Monocle.Lens as Lens exposing (Lens)\nimport Monocle.Optional as Optional exposing (Optional)\nimport Monocle.Prism as Prism exposing (Prism)\nimport Monocle.Traversal as Traversal exposing (Traversal)\n\n\n{-| pipeline-friendly composition between two Iso\n\n    ab : Iso A B\n    ab = ..\n\n    bc : Iso B C\n    bc = ..\n\n    ac : Iso A C\n    ac =\n      ab\n        |> ComposeIso.isoWithIso bc\n\n-}\nisoWithIso : Iso b c -> Iso a b -> Iso a c\nisoWithIso inner outer =\n    Iso.compose outer inner\n\n\n{-| pipeline-friendly composition between an outer Iso and an inner Prism\n(the result is a Prism)\n\n    ab : Iso A B\n    ab = ..\n\n    bc : Prism B C\n    bc = ..\n\n    ac : Prism A C\n    ac =\n      ab\n        |> ComposeIso.isoWithPrism bc\n\n-}\nisoWithPrism : Prism b c -> Iso a b -> Prism a c\nisoWithPrism inner outer =\n    let\n        getOption =\n            outer.get >> inner.getOption\n\n        reverseGet =\n            inner.reverseGet >> outer.reverseGet\n    in\n    Prism getOption reverseGet\n\n\n{-| pipeline-friendly composition between an outer Iso and an inner Traversal\n(the result is a Traversal)\n\n    ab : Iso A B\n    ab = ..\n\n    bc : Traversal B C\n    bc = ..\n\n    ac : Traversal A C\n    ac =\n      ab\n        |> ComposeIso.isoWithTraversal bc\n\n-}\nisoWithTraversal : Traversal b c -> Iso a b -> Traversal a c\nisoWithTraversal inner outer transformation =\n    Iso.modify outer (Traversal.modify inner transformation)\n\n\n{-| pipeline-friendly composition between an outer Iso and an inner Lens\n(the result is a Lens)\n\n    ab : Iso A B\n    ab = ..\n\n    bc : Lens B C\n    bc = ..\n\n    ac : Lens A C\n    ac =\n      ab\n        |> ComposeIso.isoWithLens bc\n\n-}\nisoWithLens : Lens b c -> Iso a b -> Lens a c\nisoWithLens inner outer =\n    let\n        get =\n            outer.get >> inner.get\n\n        set c =\n            Iso.modify outer (inner.set c)\n    in\n    Lens get set\n\n\n{-| pipeline-friendly composition between an outer Iso and an inner Optional\n(the result is an Optional)\n\n    ab : Iso A B\n    ab = ..\n\n    bc : Optional B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> ComposeIso.isoWithOptional bc\n\n-}\nisoWithOptional : Optional b c -> Iso a b -> Optional a c\nisoWithOptional inner outer =\n    let\n        getOption =\n            outer.get >> inner.getOption\n\n        set c =\n            Iso.modify outer (inner.set c)\n    in\n    Optional getOption set\n\n\n{-| pipeline-friendly composition between an outer Prism and an inner Iso\n(the result is a Prism)\n\n    ab : Prism A B\n    ab = ..\n\n    bc : Iso B C\n    bc = ..\n\n    ac : Prism A C\n    ac =\n      ab\n        |> ComposePrism.prismWithIso bc\n\n-}\nprismWithIso : Iso b c -> Prism a b -> Prism a c\nprismWithIso inner outer =\n    let\n        getOption =\n            outer.getOption >> Maybe.map inner.get\n\n        reverseGet =\n            inner.reverseGet >> outer.reverseGet\n    in\n    Prism getOption reverseGet\n\n\n{-| pipeline-friendly composition between two Prisms\n\n    ab : Prism A B\n    ab = ..\n\n    bc : Prism B C\n    bc = ..\n\n    ac : Prism A C\n    ac =\n      ab\n        |> ComposePrism.prismWithPrism bc\n\n-}\nprismWithPrism : Prism b c -> Prism a b -> Prism a c\nprismWithPrism inner outer =\n    Prism.compose outer inner\n\n\n{-| pipeline-friendly composition between an outer Prism and an inner Lens\n(the result is an Optional)\n\n    ab : Prism A B\n    ab = ..\n\n    bc : Lens B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> ComposePrism.prismWithLens bc\n\n-}\nprismWithLens : Lens b c -> Prism a b -> Optional a c\nprismWithLens inner outer =\n    let\n        getOption =\n            outer.getOption >> Maybe.map inner.get\n\n        set c =\n            Prism.modify outer (inner.set c)\n    in\n    Optional getOption set\n\n\n{-| pipeline-friendly composition between an outer Prism and an inner Optional\n(the result is an Optional)\n\n    ab : Prism A B\n    ab = ..\n\n    bc : Optional B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> ComposePrism.prismWithOptional bc\n\n-}\nprismWithOptional : Optional b c -> Prism a b -> Optional a c\nprismWithOptional inner outer =\n    let\n        getOption =\n            outer.getOption >> Maybe.andThen inner.getOption\n\n        set c =\n            Prism.modify outer (inner.set c)\n    in\n    Optional getOption set\n\n\n{-| pipeline-friendly composition between an outer Prism and an inner Traversal\n(the result is a Traversal)\n\n    ab : Prism A B\n    ab = ..\n\n    bc : Traversal B C\n    bc = ..\n\n    ac : Traversal A C\n    ac =\n      ab\n        |> ComposePrism.prismWithTraversal bc\n\n-}\nprismWithTraversal : Traversal b c -> Prism a b -> Traversal a c\nprismWithTraversal inner outer transformation =\n    Prism.modify outer (Traversal.modify inner transformation)\n\n\n{-| pipeline-friendly composition between an outer Lens and an inner Iso\n(the result is a Lens)\n\n    ab : Lens A B\n    ab = ..\n\n    bc : Iso B C\n    bc = ..\n\n    ac : Lens A C\n    ac =\n      ab\n        |> Compose.lensWithIso bc\n\n-}\nlensWithIso : Iso b c -> Lens a b -> Lens a c\nlensWithIso inner outer =\n    let\n        get =\n            outer.get >> inner.get\n\n        set c =\n            outer.set (inner.reverseGet c)\n    in\n    Lens get set\n\n\n{-| pipeline-friendly composition between an outer Lens and an inner Prism\n(the result is an Optional)\n\n    ab : Lens A B\n    ab = ..\n\n    bc : Prism B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> Compose.lensWithPrism bc\n\n-}\nlensWithPrism : Prism b c -> Lens a b -> Optional a c\nlensWithPrism inner outer =\n    let\n        getOption =\n            outer.get >> inner.getOption\n\n        set c =\n            outer.set (inner.reverseGet c)\n    in\n    Optional getOption set\n\n\n{-| pipeline-friendly composition between two Lenses\n\n    ab : Lens A B\n    ab = ..\n\n    bc : Lens B C\n    bc = ..\n\n    ac : Lens A C\n    ac =\n      ab\n        |> Compose.lensWithLens bc\n\n-}\nlensWithLens : Lens b c -> Lens a b -> Lens a c\nlensWithLens inner outer =\n    Lens.compose outer inner\n\n\n{-| pipeline-friendly composition between an outer Lens and an inner Optional\n(the result is an Optional)\n\n    ab : Lens A B\n    ab = ..\n\n    bc : Optional B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> Compose.lensWithOptional bc\n\n-}\nlensWithOptional : Optional b c -> Lens a b -> Optional a c\nlensWithOptional inner outer =\n    let\n        getOption =\n            outer.get >> inner.getOption\n\n        set c =\n            Lens.modify outer (inner.set c)\n    in\n    Optional getOption set\n\n\n{-| pipeline-friendly composition between an outer Lens and an inner Traversal\n(the result is an Traversal)\n\n    ab : Lens A B\n    ab = ..\n\n    bc : Traversal B C\n    bc = ..\n\n    ac : Traversal A C\n    ac =\n      ab\n        |> Compose.lensWithTraversal bc\n\n-}\nlensWithTraversal : Traversal b c -> Lens a b -> Traversal a c\nlensWithTraversal inner outer transformation =\n    Lens.modify outer (Traversal.modify inner transformation)\n\n\n{-| pipeline-friendly composition between an outer Optional and an inner Iso\n(the result is an Optional)\n\n    ab : Optional A B\n    ab = ..\n\n    bc : Iso B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> ComposeOptional.optionalWithIso bc\n\n-}\noptionalWithIso : Iso b c -> Optional a b -> Optional a c\noptionalWithIso inner outer =\n    let\n        getOption =\n            outer.getOption >> Maybe.map inner.get\n\n        set c =\n            outer.set (inner.reverseGet c)\n    in\n    Optional getOption set\n\n\n{-| pipeline-friendly composition between an outer Optional and an inner Prism\n(the result is an Optional)\n\n    ab : Optional A B\n    ab = ..\n\n    bc : Prism B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> ComposeOptional.withPrism bc\n\n-}\noptionalWithPrism : Prism b c -> Optional a b -> Optional a c\noptionalWithPrism inner outer =\n    let\n        getOption =\n            outer.getOption >> Maybe.andThen inner.getOption\n\n        set c =\n            outer.set (inner.reverseGet c)\n    in\n    Optional getOption set\n\n\n{-| pipeline-friendly composition between an outer Optional and an inner Lens\n(the result is an Optional)\n\n    ab : Optional A B\n    ab = ..\n\n    bc : Lens B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> ComposeOptional.optionalWithLens bc\n\n-}\noptionalWithLens : Lens b c -> Optional a b -> Optional a c\noptionalWithLens inner outer =\n    let\n        getOption =\n            outer.getOption >> Maybe.map inner.get\n\n        set c =\n            Optional.modify outer (inner.set c)\n    in\n    Optional getOption set\n\n\n{-| pipeline-friendly composition between two Optionals\n\n    ab : Optional A B\n    ab = ..\n\n    bc : Optional B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> ComposeOptional.optionalWithOptional bc\n\n-}\noptionalWithOptional : Optional b c -> Optional a b -> Optional a c\noptionalWithOptional inner outer =\n    Optional.compose outer inner\n\n\n{-| pipeline-friendly composition between an outer Optional and an inner Traversal\n(the result is a Optional)\n\n    ab : Optional A B\n    ab = ..\n\n    bc : Traversal B C\n    bc = ..\n\n    ac : Optional A C\n    ac =\n      ab\n        |> ComposeOptional.optionalWithTraversal bc\n\n-}\noptionalWithTraversal : Traversal b c -> Optional a b -> Traversal a c\noptionalWithTraversal inner outer transformation =\n    Optional.modify outer (Traversal.modify inner transformation)\n\n\n{-| pipeline-friendly composition between an outer Traversal and an inner Iso\n(the result is a Traversal)\n\n    ab : Traversal A B\n    ab = ..\n\n    bc : Iso B C\n    bc = ..\n\n    ac : Traversal A C\n    ac =\n      ab\n        |> ComposeTraversal.traversalWithIso bc\n\n-}\ntraversalWithIso : Iso b c -> Traversal a b -> Traversal a c\ntraversalWithIso inner outer transformation =\n    Traversal.modify outer (Iso.modify inner transformation)\n\n\n{-| pipeline-friendly composition between an outer Traversal and an inner Lens\n(the result is a Traversal)\n\n    ab : Traversal A B\n    ab = ..\n\n    bc : Lens B C\n    bc = ..\n\n    ac : Traversal A C\n    ac =\n      ab\n        |> ComposeTraversal.traversalWithLens bc\n\n-}\ntraversalWithLens : Lens b c -> Traversal a b -> Traversal a c\ntraversalWithLens inner outer transformation =\n    Traversal.modify outer (Lens.modify inner transformation)\n\n\n{-| pipeline-friendly composition between an outer Traversal and an inner Optional\n(the result is a Traversal)\n\n    ab : Traversal A B\n    ab = ..\n\n    bc : Optional B C\n    bc = ..\n\n    ac : Traversal A C\n    ac =\n      ab\n        |> ComposeTraversal.traversalWithOptional bc\n\n-}\ntraversalWithOptional : Optional b c -> Traversal a b -> Traversal a c\ntraversalWithOptional inner outer transformation =\n    Traversal.modify outer (Optional.modify inner transformation)\n\n\n{-| pipeline-friendly composition between an outer Traversal and an inner Prism\n(the result is a Traversal)\n\n    ab : Traversal A B\n    ab = ..\n\n    bc : Prism B C\n    bc = ..\n\n    ac : Traversal A C\n    ac =\n      ab\n        |> ComposeTraversal.traversalWithPrism bc\n\n-}\ntraversalWithPrism : Prism b c -> Traversal a b -> Traversal a c\ntraversalWithPrism inner outer transformation =\n    Traversal.modify outer (Prism.modify inner transformation)\n\n\n{-| pipeline-friendly composition between two Traversals\n(the result is a Traversal)\n\n    ab : Traversal A B\n    ab = ..\n\n    bc : Traversal B C\n    bc = ..\n\n    ac : Traversal A C\n    ac =\n      ab\n        |> ComposeTraversal.traversalWithTraversal bc\n\n-}\ntraversalWithTraversal : Traversal b c -> Traversal a b -> Traversal a c\ntraversalWithTraversal inner outer transformation =\n    Traversal.modify outer (Traversal.modify inner transformation)\n"
  },
  {
    "path": "src/Monocle/Iso.elm",
    "content": "module Monocle.Iso exposing\n    ( Iso\n    , reverse, modify, compose\n    )\n\n{-| An Iso is a tool which converts elements of type A into elements of type B and back without loss.\n\n\n# Definition\n\n@docs Iso\n\n\n# Laws\n\n    Identity:  \\x -> iso.get(iso.reverseGet x) == x\n    Reversed:  \\x -> iso.reverseGet(iso.get x) == x\n\n\n# Example\n\n    string2CharListIso : Iso String (List Char)\n    string2CharListIso =\n        Iso String.toList String.fromList\n\n    (string2CharListIso.get \"ABcdE\") == ['A','B','c','d','E']\n    (string2CharListIso.reverseGet ['A','B','c','d','E']) == \"ABcdE\"\n\n\n# Derived methods\n\n@docs reverse, modify, compose\n\n-}\n\n\n{-| In order to create an `Iso` we need to supply two total functions: `get` and `reverseGet`\n-}\ntype alias Iso a b =\n    { get : a -> b\n    , reverseGet : b -> a\n    }\n\n\n{-| Creates reversed `Iso b a`, exchanges functions `get` and `reverseGet`\n\n        .get (Iso.reversed someiso) == someiso.reverseGet\n        .reverseGet (Iso.reversed someiso) == someiso.get\n        Iso.compose someiso (Iso.reversed someiso) == Iso identity identity\n\n-}\nreverse : Iso a b -> Iso b a\nreverse iso =\n    Iso iso.reverseGet iso.get\n\n\n{-| Modifies given function `(b -> b)` to be `(a -> a)` using `Iso a b`\n\n        someiso = Iso String.toList String.fromList\n        somefx xs =  '@' :: xs\n        modified = Iso.modify someiso somefx\n        (modified \"artur\") == \"@artur\"\n\n-}\nmodify : Iso a b -> (b -> b) -> a -> a\nmodify iso f =\n    iso.get >> f >> iso.reverseGet\n\n\n{-| Composes `Iso a b` with `Iso b c` and returns `Iso a c`\n-}\ncompose : Iso a b -> Iso b c -> Iso a c\ncompose outer inner =\n    Iso (outer.get >> inner.get) (inner.reverseGet >> outer.reverseGet)\n"
  },
  {
    "path": "src/Monocle/Lens.elm",
    "content": "module Monocle.Lens exposing\n    ( Lens\n    , compose, modify, modify2, modify3, modifyAndMerge, zip, tuple, tuple3\n    , fromIso\n    )\n\n{-| A Lens is a functional concept which solves a very common problem:\nhow to easily update a complex immutable structure,\nfor this purpose Lens acts as a zoom into a record.\n\n\n# Definition\n\n@docs Lens\n\n\n# Example\n\n    addressStreetNameLens : Lens Address String\n    addressStreetNameLens =\n        let\n            get a =\n                a.streetName\n\n            set sn a =\n                { a | streetName = sn }\n        in\n        Lens get set\n\n    placeAddressLens : Lens Place Address\n    placeAddressLens =\n        let\n            get p =\n                p.address\n\n            set a p =\n                { p | address = a }\n        in\n        Lens get set\n\n    placeStreetName : Lens Place String\n    placeStreetName =\n        compose placeAddressLens addressStreetNameLens\n\n\n# Derived methods\n\n@docs compose, modify, modify2, modify3, modifyAndMerge, zip, tuple, tuple3\n\n\n# Conversion\n\n@docs fromIso\n\n-}\n\nimport Dict exposing (Dict)\nimport Monocle.Iso exposing (Iso)\n\n\n{-| In order to create Lens we need to supply 2 functions: set and get\n-}\ntype alias Lens a b =\n    { get : a -> b\n    , set : b -> a -> a\n    }\n\n\n{-| Composes `Lens a b` with `Lens b c` and returns `Lens a c`\n-}\ncompose : Lens a b -> Lens b c -> Lens a c\ncompose outer inner =\n    let\n        set c a =\n            outer.get a |> inner.set c |> (\\b -> outer.set b a)\n    in\n    Lens (outer.get >> inner.get) set\n\n\n{-| Modifies given function `(b -> b)` to be `(a -> a)` using `Lens a b`\n\n    addressStreetNameLens = Lens Address String\n    fx streetName = String.reverse streetName\n    fx2 = Lens.modify addressStreetNameLens fx\n    fx2 {streetName=\"abcdef\"} == {streetName=\"fedcba\"}\n\n-}\nmodify : Lens a b -> (b -> b) -> a -> a\nmodify lens f =\n    let\n        mf a =\n            lens.get a |> f |> (\\b -> lens.set b a)\n    in\n    mf\n\n\n{-| Modifies given function `(b,d) -> (b,d)` to be `(a,c) -> (a,c)` using `Lens a b` and `Lens c d`\n-}\nmodify2 : Lens a b -> Lens c d -> (( b, d ) -> ( b, d )) -> ( a, c ) -> ( a, c )\nmodify2 lens1 lens2 fx =\n    let\n        mf ( a, c ) =\n            ( lens1.get a, lens2.get c ) |> fx |> (\\( b, d ) -> ( lens1.set b a, lens2.set d c ))\n    in\n    mf\n\n\n{-| Modifies given function `(b,d,f) -> (b,d,f)` to be `(a,c,e) -> (a,c,e)` using `Lens a b` and `Lens c d` and `Lens e f`\n-}\nmodify3 : Lens a b -> Lens c d -> Lens e f -> (( b, d, f ) -> ( b, d, f )) -> ( a, c, e ) -> ( a, c, e )\nmodify3 lens1 lens2 lens3 fx =\n    let\n        mf ( a, c, e ) =\n            ( lens1.get a, lens2.get c, lens3.get e ) |> fx |> (\\( b, d, f ) -> ( lens1.set b a, lens2.set d c, lens3.set f e ))\n    in\n    mf\n\n\n{-| Casts `Iso a b` to `Lens a b`\n-}\nfromIso : Iso a b -> Lens a b\nfromIso iso =\n    let\n        set b _ =\n            iso.reverseGet b\n    in\n    Lens iso.get set\n\n\n{-| Zips `Lens a c` with `Lens b d` to form Lens ( a, b ) ( c, d )\n-}\nzip : Lens a c -> Lens b d -> Lens ( a, b ) ( c, d )\nzip left right =\n    let\n        get ( a, b ) =\n            ( left.get a, right.get b )\n\n        set ( c, d ) ( a, b ) =\n            ( left.set c a, right.set d b )\n    in\n    Lens get set\n\n\n{-| Modifies given function `(b -> (b,c))` to be `(a,c) -> (a,c)` using `Lens a b` and `merge` function\n-}\nmodifyAndMerge : Lens a b -> (b -> ( b, c )) -> (c -> c -> c) -> ( a, c ) -> ( a, c )\nmodifyAndMerge lens fx merge =\n    let\n        mf ( a, c ) =\n            lens.get a\n                |> fx\n                |> (\\( b, c1 ) -> ( lens.set b a, merge c c1 ))\n    in\n    mf\n\n\n{-| Tuple `Lens a b` with `Lens a c` and returns `Lens a (b,c)`\n-}\ntuple : Lens a b -> Lens a c -> Lens a ( b, c )\ntuple left right =\n    let\n        get a =\n            ( left.get a, right.get a )\n\n        set ( b, c ) a =\n            right.set c (left.set b a)\n    in\n    Lens get set\n\n\n{-| Tuple `Lens a b` with `Lens a c` with `Lens a d` and returns `Lens a (b,c,d)`\n-}\ntuple3 : Lens a b -> Lens a c -> Lens a d -> Lens a ( b, c, d )\ntuple3 first second third =\n    let\n        get a =\n            ( first.get a, second.get a, third.get a )\n\n        set ( b, c, d ) a =\n            third.set d (second.set c (first.set b a))\n    in\n    Lens get set\n"
  },
  {
    "path": "src/Monocle/Optional.elm",
    "content": "module Monocle.Optional exposing\n    ( Optional\n    , compose, composeLens, modifyOption, modify, modify2, modify3, zip, tuple, tuple3\n    , fromPrism, fromLens\n    )\n\n{-| A Optional is a weaker Lens and a weaker Prism\n\n\n# Definition\n\n@docs Optional\n\n\n# Derived methods\n\n@docs compose, composeLens, modifyOption, modify, modify2, modify3, zip, tuple, tuple3\n\n\n# Conversion\n\n@docs fromPrism, fromLens\n\n\n# Example\n\n    addressRegionOptional : Optional Address String\n    addressRegionOptional =\n        let\n            getOption a =\n                a.region\n\n            set r a =\n                { a | region = Just r }\n        in\n        Optional getOption set\n\n-}\n\nimport Monocle.Lens exposing (Lens)\nimport Monocle.Prism exposing (Prism)\n\n\nflip : (a -> b -> c) -> b -> a -> c\nflip f b a =\n    f a b\n\n\n{-| In order to create Optional we need to supply 2 functions: set and getOption\n-}\ntype alias Optional a b =\n    { getOption : a -> Maybe b\n    , set : b -> a -> a\n    }\n\n\n{-| Composes `Optional a b` with `Optional b c` and returns `Optional a c`\n\n    string2IntPrism : Prism String Int\n    string2IntPrism =\n        Prism String.toInt String.fromInt\n\n    addressRegionIntOptional : Optional Address Int\n    addressRegionIntOptional =\n        compose addressRegionOptional (fromPrism string2IntPrism)\n\n-}\ncompose : Optional a b -> Optional b c -> Optional a c\ncompose outer inner =\n    let\n        set c a =\n            outer.getOption a\n                |> Maybe.map (inner.set c >> flip outer.set a)\n                |> Maybe.withDefault a\n\n        getOption a =\n            case outer.getOption a of\n                Just x ->\n                    x |> inner.getOption\n\n                Nothing ->\n                    Nothing\n    in\n    Optional getOption set\n\n\n{-| Composes `Optional a b` with `Lens b c` and returns `Optional a c`\n\n    string2CharListIso : Iso String (List Char)\n    string2CharListIso =\n        Iso String.toList String.fromList\n\n    addressRegionListCharOptional : Optional Address (List Char)\n    addressRegionListCharOptional =\n        composeLens addressRegionOptional (fromIso string2CharListIso)\n\n-}\ncomposeLens : Optional a b -> Lens b c -> Optional a c\ncomposeLens opt lens =\n    let\n        set c a =\n            opt.getOption a\n                |> Maybe.map (lens.set c >> flip opt.set a)\n                |> Maybe.withDefault a\n\n        getOption a =\n            case opt.getOption a of\n                Just b ->\n                    b |> lens.get |> Just\n\n                Nothing ->\n                    Nothing\n    in\n    Optional getOption set\n\n\n{-| Modifies given function `(b -> b)` to be `(a -> Maybe a)` using `Optional a b`\n\n        modifyRegion: String -> String\n        modifyRegion region = String.reverse region\n\n        modifyAddressRegion: Address -> Maybe Address\n        modifyAddressRegion address = Optional.modifyOption addressRegionOptional modifyRegion address\n\n-}\nmodifyOption : Optional a b -> (b -> b) -> a -> Maybe a\nmodifyOption opt fx =\n    let\n        mf a =\n            opt.getOption a |> Maybe.map (fx >> flip opt.set a)\n    in\n    mf\n\n\n{-| Modifies given function `(b -> b)` to be `(a -> a)` using `Optional a b`\n\n        modifyRegion: String -> String\n        modifyRegion region = String.reverse region\n\n        modifyAddressRegion: Address -> Address\n        modifyAddressRegion address = Optional.modify addressRegionOptional modifyRegion address\n\n-}\nmodify : Optional a b -> (b -> b) -> a -> a\nmodify opt fx =\n    let\n        mf a =\n            modifyOption opt fx a |> Maybe.withDefault a\n    in\n    mf\n\n\n{-| Modifies given function `(b,d) -> (b,d)` to be `(a,c) -> (a,c)` using `Optional a b` and `Optional c d`\n\n    Function will be invoked ONLY when for ALL arguments `a` and `c` method `Optional.getOption` returns some value.\n\n-}\nmodify2 : Optional a b -> Optional c d -> (( b, d ) -> ( b, d )) -> ( a, c ) -> ( a, c )\nmodify2 opt1 opt2 fx =\n    let\n        mf ( a, c ) =\n            case ( opt1.getOption a, opt2.getOption c ) of\n                ( Just b, Just d ) ->\n                    ( b, d ) |> fx |> (\\( b1, d1 ) -> ( opt1.set b1 a, opt2.set d1 c ))\n\n                _ ->\n                    ( a, c )\n    in\n    mf\n\n\n{-| Modifies given function `( b, d, f ) -> ( b, d, f )` to be `( a, c, e ) -> ( a, c, e )` using `Optional a b` and `Optional c d` and `Optional e f`\n\n    Function will be invoked ONLY when for ALL arguments `a`,`c`,`f` method `Optional.getOption` returns some value.\n\n-}\nmodify3 : Optional a b -> Optional c d -> Optional e f -> (( b, d, f ) -> ( b, d, f )) -> ( a, c, e ) -> ( a, c, e )\nmodify3 opt1 opt2 opt3 fx =\n    let\n        mf ( a, c, e ) =\n            case ( opt1.getOption a, opt2.getOption c, opt3.getOption e ) of\n                ( Just b, Just d, Just f ) ->\n                    ( b, d, f ) |> fx |> (\\( b1, d1, f1 ) -> ( opt1.set b1 a, opt2.set d1 c, opt3.set f1 e ))\n\n                _ ->\n                    ( a, c, e )\n    in\n    mf\n\n\n{-| Casts `Prism a b` to `Optional a b`\n\n    string2IntPrism : Prism String Int\n    string2IntPrism =\n        Prism String.toInt String.fromInt\n\n    stringIntOptional : Optional String Int\n    stringIntOptional =\n        fromPrism string2IntPrism\n\n-}\nfromPrism : Prism a b -> Optional a b\nfromPrism prism =\n    let\n        set b _ =\n            prism.reverseGet b\n    in\n    Optional prism.getOption set\n\n\n{-| Casts `Lens a b` to `Optional a b` where `getOption` will return always `Just`\n-}\nfromLens : Lens a b -> Optional a b\nfromLens lens =\n    let\n        getOption a =\n            Just (lens.get a)\n    in\n    Optional getOption lens.set\n\n\n{-| Zip `Optional a c` with `Optional b d` to form Optional for the pairs ( a, b ) ( c, d )\n-}\nzip : Optional a c -> Optional b d -> Optional ( a, b ) ( c, d )\nzip left right =\n    let\n        getOption ( a, b ) =\n            left.getOption a\n                |> Maybe.andThen\n                    (\\c ->\n                        right.getOption b\n                            |> Maybe.map (\\d -> ( c, d ))\n                    )\n\n        set ( c, d ) ( a, b ) =\n            ( left.set c a, right.set d b )\n    in\n    Optional getOption set\n\n\n{-| Tuple `Optional a b` with `Optional a c` and returns `Optional a (b,c)`\n\n    Method `Optional.getOption` returns pair of values only when both given optionals return some value.\n\n-}\ntuple : Optional a b -> Optional a c -> Optional a ( b, c )\ntuple left right =\n    let\n        getOption a =\n            case ( left.getOption a, right.getOption a ) of\n                ( Just b, Just d ) ->\n                    Just ( b, d )\n\n                _ ->\n                    Nothing\n\n        set ( b, c ) a =\n            right.set c (left.set b a)\n    in\n    Optional getOption set\n\n\n{-| Tuple `Optional a b` with `Optional a c` with `Optional a d` and returns `Optional a (b,c,d)`\n\n    Method `Optional.getOption` returns triple of values only when all given optionals return some value.\n\n-}\ntuple3 : Optional a b -> Optional a c -> Optional a d -> Optional a ( b, c, d )\ntuple3 first second third =\n    let\n        getOption a =\n            case ( first.getOption a, second.getOption a, third.getOption a ) of\n                ( Just b, Just d, Just f ) ->\n                    Just ( b, d, f )\n\n                _ ->\n                    Nothing\n\n        set ( b, c, d ) a =\n            first.set b a |> second.set c |> third.set d\n    in\n    Optional getOption set\n"
  },
  {
    "path": "src/Monocle/Prism.elm",
    "content": "module Monocle.Prism exposing\n    ( Prism\n    , isMatching, modify, modifyOption, compose, composeIso\n    , fromIso\n    )\n\n{-| A Prism is a tool which optionally converts elements of type A into elements of type B and back.\n\n\n# Definition\n\n@docs Prism\n\n\n# Example\n\n    string2IntPrism : Prism String Int\n    string2IntPrism =\n        Prism String.toInt String.fromInt\n\n    string2IntPrism.getOption \"17896\" == Just 17896\n    string2IntPrism.getOption \"1a896\" == Nothing\n    string2IntPrism.reverseGet 1626767 = \"1626767\"\n\n\n# Derived methods\n\n@docs isMatching, modify, modifyOption, compose, composeIso\n\n\n# Conversion\n\n@docs fromIso\n\n-}\n\nimport Maybe\nimport Monocle.Iso exposing (Iso)\n\n\n{-| In order to create a `Prism` we need to supply two functions: `getOption` and `reverseGet`\n-}\ntype alias Prism a b =\n    { getOption : a -> Maybe b\n    , reverseGet : b -> a\n    }\n\n\n{-| Checks if value of type `A` has matching element of type 'B'\n\n        Monocle.Prism.isMatching string2IntPrism \"abc\" == False\n        Monocle.Prism.isMatching string2IntPrism \"123\" == True\n\n-}\nisMatching : Prism a b -> a -> Bool\nisMatching prism a =\n    case prism.getOption a of\n        Just c ->\n            True\n\n        Nothing ->\n            False\n\n\n{-| Modifies given function `(b -> b)` to be `(a -> Maybe a)` using `Prism a b`\n\n        fx i = i * 2\n        modified = Monocle.Prism.modify string2IntPrism fx\n        modified \"22\" == Just \"44\"\n        modified \"abc\" == Nothing\n\n-}\nmodifyOption : Prism a b -> (b -> b) -> a -> Maybe a\nmodifyOption prism f =\n    prism.getOption >> Maybe.map (f >> prism.reverseGet)\n\n\n{-| Modifies given function `(b -> b)` to be `(a -> a)` using `Prism a b`\n\n        fx i = i * 2\n        modified = Monocle.Prism.modify string2IntPrism fx\n        modified \"22\" == \"44\"\n        modified \"abc\" == \"abc\"\n\n-}\nmodify : Prism a b -> (b -> b) -> a -> a\nmodify prism f =\n    let\n        m x =\n            modifyOption prism f x |> Maybe.withDefault x\n    in\n    m\n\n\n{-| Composes `Prism a b` with `Prism b c` and returns `Prism a c`\n\n        prism = Monocle.Prism.compose string2FloatPrism float2IntPrism\n        prism.getOption \"22\" == Just 22\n        prism.getOption \"22.2\" == Nothing\n        prism.getOption \"22a\" == Nothing\n        prism.getOption \"abc\" == Nothing\n\n-}\ncompose : Prism a b -> Prism b c -> Prism a c\ncompose outer inner =\n    let\n        getOption x =\n            case outer.getOption x of\n                Just y ->\n                    y |> inner.getOption\n\n                Nothing ->\n                    Nothing\n    in\n    Prism getOption (inner.reverseGet >> outer.reverseGet)\n\n\n{-| Composes `Prism a b` with `Iso b c` and returns `Prism a c`\n\n        iso = Iso ((*) 10) ((//) 10)\n        prism = Monocle.Prism.composeIso string2IntPrism iso\n        prism.getOption \"22\" == Just 220\n        prism.getOption \"22.2\" == Nothing\n        prism.getOption \"22a\" == Nothing\n        prism.getOption \"abc\" == Nothing\n\n-}\ncomposeIso : Prism a b -> Iso b c -> Prism a c\ncomposeIso outer inner =\n    let\n        getOption x =\n            case outer.getOption x of\n                Just y ->\n                    y |> inner.get |> Just\n\n                Nothing ->\n                    Nothing\n    in\n    Prism getOption (inner.reverseGet >> outer.reverseGet)\n\n\n{-| Casts `Iso a b` to `Prism a b`\n-}\nfromIso : Iso a b -> Prism a b\nfromIso iso =\n    Prism (iso.get >> Just) iso.reverseGet\n"
  },
  {
    "path": "src/Monocle/Traversal.elm",
    "content": "module Monocle.Traversal exposing\n    ( Traversal\n    , list, array, some, modify\n    )\n\n{-| A Traversal is like an Optional that may modify multiple sub-elements, keeping the overlaying structure as is.\n\n\n# Definition\n\n@docs Traversal\n\n\n# Example\n\n    personsAge : Lens Person Int\n    personsAge =\n        let\n            get a =\n                a.age\n\n            set b a =\n                { a | age = b }\n        in\n        Lens get set\n\n    jeffs : Traversal (List Person) Person\n    jeffs =\n        Traversal.some Traversal.list (\\p -> p.name == \"Jeff\")\n\n    jeffsAges : Traversal (List Person) Int\n    jeffsAges =\n        jeffs\n            |> Compose.traversalWithLens personsAge\n\n\n# Derived methods\n\n@docs list, array, some, modify\n\n-}\n\nimport Array exposing (Array)\n\n\n{-| To create a Traversal, you just need to provide a function\nthat applies a transformation function to some or all elements\nin the parent structure.\n-}\ntype alias Traversal a b =\n    (b -> b) -> a -> a\n\n\n{-| A basic traversal that affects all elements in a list\n-}\nlist : Traversal (List a) a\nlist =\n    List.map\n\n\n{-| A basic traversal that affects all elements in an array\n-}\narray : Traversal (Array a) a\narray =\n    Array.map\n\n\n{-| A traversal that, given another traversal as base, only affects\nthose traversed elements that satisfy a condition.\n\n    numbers : Traversal (List number) number\n    numbers =\n        Traversal.list\n\n    oddNumbers : Traversal (List number) number\n    oddNumbers =\n        Traversal.some numbers (\\number -> remainderBy 2 number == 1)\n\n    evenNumbers : Traversal (List number) number\n    evenNumbers =\n        Traversal.some numbers (\\number -> remainderBy 2 number == 0)\n\n-}\nsome : Traversal a b -> (b -> Bool) -> Traversal a b\nsome traversal condition transformation =\n    let\n        conditionedTransformation value =\n            if condition value then\n                transformation value\n\n            else\n                value\n    in\n    traversal conditionedTransformation\n\n\n{-| Modifies all elements traversed by `Traversal a b` using function\n`(b -> b)` in structure `a`\n\n    personsHairColor : Lens Person String\n    personsHairColor =\n        Lens .hairColor (\\b a-> { a | hairColor = b })\n\n    pauls : Traversal (List Person) Person\n    pauls =\n        Traversal.some Traversal.list (\\person -> person.firstName == 'Paul' )\n\n    paulsHairColor : Traversal (List Person) String\n    paulsHairColor =\n        pauls\n            |> Compose.traversalWithLens personsHairColor\n\n    lighten : String -> String\n    lighten hairColor =\n        \"light \" ++ hairColor\n\n    lightenPauls : List Person -> List Person\n    lightenPauls =\n        Traversal.modify pauls\n\n    lightenPauls [\n        { firstName = \"Paul\"\n        , hairColor = \"brown\"\n        },\n        { firstName = \"Jake\"\n        , hairColor = \"blond\"\n        }\n    ] == [\n        { firstName = \"Paul\"\n        , hairColor = \"light brown\"\n        },\n        { firstName = \"Jake\"\n        , hairColor = \"blond\"\n        }\n    ]\n\n-}\nmodify : Traversal a b -> (b -> b) -> a -> a\nmodify traversal =\n    traversal\n"
  },
  {
    "path": "tests/.gitignore",
    "content": "/elm-stuff/\n"
  },
  {
    "path": "tests/CommonSpec.elm",
    "content": "module CommonSpec exposing (..)\n\nimport Test exposing (..)\nimport Expect\nimport Fuzz exposing (int, tuple, string, char)\nimport Dict\nimport Maybe\nimport Array\nimport Monocle.Common exposing (dict, maybe, array, list, listToArray, id)\n\n\nall : Test\nall =\n    describe \"A Common specification\"\n        [ test_maybe\n        , test_array_just\n        , test_array_nothing\n        , test_list_just\n        , test_list_nothing\n        , test_list_to_array_get\n        , test_list_to_array_reverse_get\n        , test_dict_empty\n        , test_dict_list\n        ]\n\n\ntest_maybe : Test\ntest_maybe =\n    let\n        test s =\n            maybe.set s Nothing |> Expect.equal (Just s)\n    in\n        fuzz string \"Common.maybe should step into Maybe\" test\n\n\ntest_array_just : Test\ntest_array_just =\n    let\n        test i =\n            .getOption (array 2) (Array.fromList [ 10, 11, i, 13 ]) |> Expect.equal (Just i)\n    in\n        fuzz int \"Common.array should get some value at position 2\" test\n\n\ntest_array_nothing : Test\ntest_array_nothing =\n    let\n        test i =\n            .getOption (array 8) (Array.fromList [ i, i, i, i, i, i, i, i ]) |> Expect.equal Nothing\n    in\n        fuzz int \"Common.array should return nothing if index out of bound\" test\n\n\ntest_list_just : Test\ntest_list_just =\n    let\n        test i =\n            .getOption (list 2) [ 10, 11, i, 13 ] |> Expect.equal (Just i)\n    in\n        fuzz int \"Common.list should get some value at position 2\" test\n\n\ntest_list_nothing : Test\ntest_list_nothing =\n    let\n        test i =\n            .getOption (list 8) [ i, i, i, i, i, i, i, i ] |> Expect.equal Nothing\n    in\n        fuzz int \"Common.list should return nothing if index out of bound\" test\n\n\ntest_list_to_array_get : Test\ntest_list_to_array_get =\n    let\n        test l =\n            .get listToArray l |> Expect.equal (l |> Array.fromList)\n    in\n        fuzz (Fuzz.list int) \"Common.listToArray.get should convert a list to an array\" test\n\n\ntest_list_to_array_reverse_get : Test\ntest_list_to_array_reverse_get =\n    let\n        test a =\n            .reverseGet listToArray a |> Expect.equal (Array.toList a)\n    in\n        fuzz (Fuzz.array int) \"Common.listToArray.reverseGet should convert an array to a list\" test\n\n\ntest_dict_empty : Test\ntest_dict_empty =\n    let\n        opt =\n            dict \"mykey\"\n\n        test s =\n            opt.getOption (opt.set s Dict.empty) |> Expect.equal (Just s)\n    in\n        fuzz string \"Common.dict should set and get value by key (empty dict)\" test\n\n\ntest_dict_list : Test\ntest_dict_list =\n    let\n        opt =\n            (dict \"Tom\")\n\n        test s =\n            .getOption opt (Dict.fromList [ ( \"Tom\", s ), ( \"Alice\", \"Rabbit\" ) ]) |> Expect.equal (Just s)\n    in\n        fuzz string \"Common.dict should set and get value by key (preloaded dict)\" test\n"
  },
  {
    "path": "tests/ComposeSpec.elm",
    "content": "module ComposeSpec exposing (..)\n\nimport Array\nimport Expect\nimport Fuzz exposing (constant, float, int, intRange, list, maybe, oneOf, string, tuple, tuple3)\nimport Monocle.Compose as Compose\nimport Monocle.Iso exposing (Iso)\nimport Monocle.Lens exposing (Lens)\nimport Monocle.Optional exposing (Optional)\nimport Monocle.Prism exposing (Prism)\nimport Monocle.Traversal as Traversal\nimport Test exposing (..)\n\n\nall : Test\nall =\n    describe \"Monocle.Compose\"\n        [ test_isoWithIso\n        , test_isoWithLens\n        , test_isoWithOptional\n        , test_isoWithPrism\n        , test_isoWithTraversal\n        , test_lensWithIso\n        , test_lensWithLens\n        , test_lensWithOptional\n        , test_lensWithPrism\n        , test_lensWithTraversal\n        , test_prismWithIso\n        , test_prismWithLens\n        , test_prismWithOptional\n        , test_prismWithPrism\n        , test_prismWithTraversal\n        , test_optionalWithIso\n        , test_optionalWithLens\n        , test_optionalWithOptional\n        , test_optionalWithPrism\n        , test_optionalWithTraversal\n        , test_traversalWithIso\n        , test_traversalWithLens\n        , test_traversalWithOptional\n        , test_traversalWithPrism\n        , test_traversalWithTraversal\n        ]\n\n\ntest_isoWithIso : Test\ntest_isoWithIso =\n    let\n        isoString2CharList =\n            Iso String.toList String.fromList\n\n        isoCharList2CharArray =\n            Iso Array.fromList Array.toList\n\n        isoComposedString2CharArray =\n            isoString2CharList\n                |> Compose.isoWithIso isoCharList2CharArray\n\n        string2CharArray =\n            String.toList >> Array.fromList\n\n        test_get s =\n            s\n                |> .get isoComposedString2CharArray\n                |> Expect.equal (s |> string2CharArray)\n\n        test_reverseGet s =\n            (s |> string2CharArray)\n                |> .reverseGet isoComposedString2CharArray\n                |> Expect.equal s\n    in\n    describe \"Compose.isoWithIso\"\n        [ test_get |> fuzz string \".get\"\n        , test_reverseGet |> fuzz string \".reverseGet\"\n        ]\n\n\ntype Admin name\n    = Admin name\n\n\ntype User name\n    = User name\n\n\ntest_isoWithLens : Test\ntest_isoWithLens =\n    let\n        isoUser2Admin =\n            Iso (\\(User name) -> Admin name) (\\(Admin name) -> User name)\n\n        lensAdminName =\n            Lens (\\(Admin name) -> name) (\\name admin -> Admin name)\n\n        lensComposedUser2AdminName =\n            isoUser2Admin\n                |> Compose.isoWithLens lensAdminName\n\n        test_get name =\n            User name\n                |> .get lensComposedUser2AdminName\n                |> Expect.equal name\n\n        test_set ( oldName, newName ) =\n            User oldName\n                |> .set lensComposedUser2AdminName newName\n                |> Expect.equal (User newName)\n    in\n    describe \"Compose.isoWithLens\"\n        [ test_get |> fuzz string \".get\"\n        , test_set |> fuzz (tuple ( string, string )) \".set\"\n        ]\n\n\ntest_isoWithOptional : Test\ntest_isoWithOptional =\n    let\n        isoUser2Admin =\n            Iso (\\(User name) -> Admin name) (\\(Admin name) -> User name)\n\n        optionalAdminName =\n            Optional (\\(Admin name) -> name) (\\name admin -> Admin (Just name))\n\n        optionalComposedUser2AdminName =\n            isoUser2Admin\n                |> Compose.isoWithOptional optionalAdminName\n\n        test_getOption name =\n            User (Just name)\n                |> .getOption optionalComposedUser2AdminName\n                |> Expect.equal (Just name)\n\n        test_set ( oldName, newName ) =\n            User (Just oldName)\n                |> .set optionalComposedUser2AdminName newName\n                |> Expect.equal (User (Just newName))\n    in\n    describe \"Compose.isoWithOptional\"\n        [ test_getOption |> fuzz string \".getOption\"\n        , test_set |> fuzz (tuple ( string, string )) \".set\"\n        ]\n\n\ntest_isoWithPrism : Test\ntest_isoWithPrism =\n    let\n        isoCharList2String =\n            Iso String.fromList String.toList\n\n        prismString2Int =\n            Prism String.toInt String.fromInt\n\n        int2CharList =\n            String.fromInt >> String.toList\n\n        prismComposedCharList2Int =\n            isoCharList2String\n                |> Compose.isoWithPrism prismString2Int\n\n        test_getOption int =\n            (int |> int2CharList)\n                |> .getOption prismComposedCharList2Int\n                |> Expect.equal (Just int)\n\n        test_reverseGet int =\n            int\n                |> .reverseGet prismComposedCharList2Int\n                |> Expect.equal (int |> int2CharList)\n    in\n    describe \"Compose.isoWithPrism\"\n        [ test_getOption |> fuzz int \".getOption\"\n        , test_reverseGet |> fuzz int \".reverseGet\"\n        ]\n\n\ntest_isoWithTraversal : Test\ntest_isoWithTraversal =\n    let\n        isoString2CharList =\n            Iso String.toList String.fromList\n\n        traversalStringChars =\n            isoString2CharList\n                |> Compose.isoWithTraversal Traversal.list\n\n        shift =\n            Char.toCode >> (+) 1 >> Char.fromCode\n\n        test_modify string =\n            let\n                modified =\n                    string\n                        |> Traversal.modify traversalStringChars shift\n\n                expected =\n                    string\n                        |> String.toList\n                        |> List.map shift\n                        |> String.fromList\n            in\n            Expect.equal modified expected\n    in\n    describe \"Compose.isoWithTraversal\"\n        [ test_modify |> fuzz string \"modify\"\n        ]\n\n\ntest_lensWithIso : Test\ntest_lensWithIso =\n    let\n        lensUser2Name =\n            Lens .name (\\name user -> { user | name = name })\n\n        isoReverse =\n            Iso String.reverse String.reverse\n\n        lensUser2NameReverse =\n            lensUser2Name\n                |> Compose.lensWithIso isoReverse\n\n        test_get name =\n            { name = name }\n                |> .get lensUser2NameReverse\n                |> Expect.equal (name |> String.reverse)\n\n        test_set ( oldName, newName ) =\n            { name = oldName }\n                |> .set lensUser2NameReverse newName\n                |> Expect.equal { name = newName |> String.reverse }\n    in\n    describe \"Compose.lensWithIso\"\n        [ test_get |> fuzz string \".get\"\n        , test_set |> fuzz (tuple ( string, string )) \".set\"\n        ]\n\n\ntest_lensWithLens : Test\ntest_lensWithLens =\n    let\n        lensPerson2StreetAddress =\n            Lens .streetAddress (\\streetAddress person -> { person | streetAddress = streetAddress })\n\n        lensStreetAddress2City =\n            Lens .city (\\city streetAddress -> { streetAddress | city = city })\n\n        lensPerson2StreetAddressCity =\n            lensPerson2StreetAddress\n                |> Compose.lensWithLens lensStreetAddress2City\n\n        personify ( name, street, city ) =\n            { name = name\n            , streetAddress =\n                { street = street\n                , city = city\n                }\n            }\n\n        test_get ( name, street, city ) =\n            personify ( name, street, city )\n                |> .get lensPerson2StreetAddressCity\n                |> Expect.equal city\n\n        test_set ( ( name, street, city ), newCity ) =\n            personify ( name, street, city )\n                |> .set lensPerson2StreetAddressCity newCity\n                |> Expect.equal (personify ( name, street, newCity ))\n    in\n    describe \"Compose.lensWithLens\"\n        [ test_get |> fuzz (tuple3 ( string, string, string )) \".get\"\n        , test_set |> fuzz (tuple ( tuple3 ( string, string, string ), string )) \".set\"\n        ]\n\n\ntest_lensWithOptional : Test\ntest_lensWithOptional =\n    let\n        lensDriver2Vehicle =\n            Lens .vehicle (\\vehicle driver -> { driver | vehicle = vehicle })\n\n        optionalVehicle2LicenseNumber =\n            Optional .licenseNumber (\\licenseNumber vehicle -> { vehicle | licenseNumber = Just licenseNumber })\n\n        optionalDriver2LicenseNumber =\n            lensDriver2Vehicle\n                |> Compose.lensWithOptional optionalVehicle2LicenseNumber\n\n        vehiclify ( name, serie, licenseNumber ) =\n            { name = name\n            , vehicle =\n                { serie = serie\n                , licenseNumber = Just licenseNumber\n                }\n            }\n\n        test_getOption ( name, serie, licenseNumber ) =\n            vehiclify ( name, serie, licenseNumber )\n                |> .getOption optionalDriver2LicenseNumber\n                |> Expect.equal (Just licenseNumber)\n\n        test_set ( ( name, serie, licenseNumber ), newLicenseNumber ) =\n            vehiclify ( name, serie, licenseNumber )\n                |> .set optionalDriver2LicenseNumber newLicenseNumber\n                |> Expect.equal (vehiclify ( name, serie, newLicenseNumber ))\n    in\n    describe \"Compose.lensWithOptional\"\n        [ test_getOption |> fuzz (tuple3 ( string, string, string )) \".getOption\"\n        , test_set |> fuzz (tuple ( tuple3 ( string, string, string ), string )) \".set\"\n        ]\n\n\ntest_lensWithPrism : Test\ntest_lensWithPrism =\n    let\n        lensPerson2FirstName =\n            Lens .firstName (\\firstName person -> { person | firstName = firstName })\n\n        prismName2Number =\n            Prism String.toInt String.fromInt\n\n        optionalPerson2Number =\n            lensPerson2FirstName\n                |> Compose.lensWithPrism prismName2Number\n\n        personify ( firstName, lastName ) =\n            { firstName = firstName\n            , lastName = lastName\n            }\n\n        test_getOption ( firstName, lastName ) =\n            personify ( firstName |> String.fromInt, lastName )\n                |> .getOption optionalPerson2Number\n                |> Expect.equal (Just firstName)\n\n        test_set ( ( firstName, lastName ), newFirstName ) =\n            personify ( firstName, lastName )\n                |> .set optionalPerson2Number newFirstName\n                |> Expect.equal (personify ( newFirstName |> String.fromInt, lastName ))\n    in\n    describe \"Compose.lensWithPrism\"\n        [ test_getOption |> fuzz (tuple ( int, string )) \".getOption\"\n        , test_set |> fuzz (tuple ( tuple ( string, string ), int )) \".set\"\n        ]\n\n\ntest_lensWithTraversal : Test\ntest_lensWithTraversal =\n    let\n        lensPerson2Friends =\n            Lens .friends (\\friends person -> { person | friends = friends })\n\n        traversalPersonFriends =\n            lensPerson2Friends\n                |> Compose.lensWithTraversal Traversal.list\n\n        personify name friends =\n            { name = name\n            , friends = friends\n            }\n\n        test_modify ( name, friends ) =\n            personify name friends\n                |> Traversal.modify traversalPersonFriends String.reverse\n                |> Expect.equal (personify name (List.map String.reverse friends))\n    in\n    describe \"Compose.lensWithTraversal\"\n        [ test_modify |> fuzz (tuple ( int, list string )) \".modify\"\n        ]\n\n\ntest_prismWithIso : Test\ntest_prismWithIso =\n    let\n        prismString2Int =\n            Prism String.toInt String.fromInt\n\n        isoPlusOne =\n            Iso (\\n -> n + 1) (\\n -> n - 1)\n\n        prismIntPlusOne =\n            prismString2Int\n                |> Compose.prismWithIso isoPlusOne\n\n        test_getOption quantity =\n            (quantity |> String.fromInt)\n                |> .getOption prismIntPlusOne\n                |> Expect.equal (Just (quantity + 1))\n    in\n    describe \"Compose.prismWithIso\"\n        [ test_getOption |> fuzz int \".getOption\" ]\n\n\ntype alias Address =\n    { city : String\n    , street : Maybe String\n    }\n\n\ntype alias Coordinates =\n    { lng : Float\n    , lat : Float\n    }\n\n\ntype Location\n    = ByAddress Address\n    | ByCoordinates Coordinates\n\n\ntest_prismWithLens : Test\ntest_prismWithLens =\n    let\n        coordinates location =\n            case location of\n                ByCoordinates c ->\n                    Just c\n\n                _ ->\n                    Nothing\n\n        prismLocationToCoordinates =\n            Prism coordinates ByCoordinates\n\n        lensLng =\n            Lens .lng (\\lng c -> { c | lng = lng })\n\n        optionalLocationLng =\n            prismLocationToCoordinates\n                |> Compose.prismWithLens lensLng\n\n        test_getOption ( lng, lat ) =\n            ByCoordinates { lng = lng, lat = lat }\n                |> .getOption optionalLocationLng\n                |> Expect.equal (Just lng)\n\n        test_set ( ( lng, lat ), newLng ) =\n            ByCoordinates { lng = lng, lat = lat }\n                |> .set optionalLocationLng newLng\n                |> Expect.equal (ByCoordinates { lng = newLng, lat = lat })\n    in\n    describe \"Compose.prismWithLens\"\n        [ test_getOption |> fuzz (tuple ( float, float )) \".getOption\"\n        , test_set |> fuzz (tuple ( tuple ( float, float ), float )) \".set\"\n        ]\n\n\ntest_prismWithOptional : Test\ntest_prismWithOptional =\n    let\n        address location =\n            case location of\n                ByAddress a ->\n                    Just a\n\n                _ ->\n                    Nothing\n\n        prismLocationToAddress =\n            Prism address ByAddress\n\n        optionalStreet =\n            Optional .street (\\street a -> { a | street = Just street })\n\n        optionalLocationStreet =\n            prismLocationToAddress\n                |> Compose.prismWithOptional optionalStreet\n\n        test_getOption ( street, city ) =\n            ByAddress { street = Just street, city = city }\n                |> .getOption optionalLocationStreet\n                |> Expect.equal (Just street)\n\n        test_set ( ( street, city ), newStreet ) =\n            ByAddress { street = Just street, city = city }\n                |> .set optionalLocationStreet newStreet\n                |> Expect.equal (ByAddress { street = Just newStreet, city = city })\n    in\n    describe \"Compose.prismWithOptional\"\n        [ test_getOption |> fuzz (tuple ( string, string )) \".getOption\"\n        , test_set |> fuzz (tuple ( tuple ( string, string ), string )) \".set\"\n        ]\n\n\ntype Option\n    = OptionOne\n    | OptionTwo\n    | OptionThree\n\n\ntest_prismWithPrism : Test\ntest_prismWithPrism =\n    let\n        toOption n =\n            case n of\n                1 ->\n                    Just OptionOne\n\n                2 ->\n                    Just OptionTwo\n\n                3 ->\n                    Just OptionThree\n\n                _ ->\n                    Nothing\n\n        fromOption option =\n            case option of\n                OptionOne ->\n                    1\n\n                OptionTwo ->\n                    2\n\n                OptionThree ->\n                    3\n\n        anyOption =\n            [ OptionOne\n            , OptionTwo\n            , OptionThree\n            ]\n                |> List.map constant\n\n        prismString2Int =\n            Prism String.toInt String.fromInt\n\n        prismInt2Option =\n            Prism toOption fromOption\n\n        prismString2Option =\n            prismString2Int\n                |> Compose.prismWithPrism prismInt2Option\n\n        test_getOption n =\n            (n |> String.fromInt)\n                |> .getOption prismString2Option\n                |> Expect.equal (n |> toOption)\n\n        test_reverseGet option =\n            option\n                |> .reverseGet prismString2Option\n                |> Expect.equal (option |> fromOption |> String.fromInt)\n    in\n    describe \"Compose.prismWithPrism\"\n        [ test_getOption |> fuzz (intRange 1 3) \".getOption\"\n        , test_reverseGet |> fuzz (oneOf anyOption) \".reverseGet\"\n        ]\n\n\ntype PseudoList a\n    = None\n    | One a\n    | Two a a\n\n\ntest_prismWithTraversal : Test\ntest_prismWithTraversal =\n    let\n        toShortList items =\n            case items of\n                [] ->\n                    Just []\n\n                [ x ] ->\n                    Just [ x ]\n\n                [ x, y ] ->\n                    Just [ x, y ]\n\n                _ ->\n                    Nothing\n\n        fromShortList items =\n            items\n\n        prismShortList =\n            Prism toShortList fromShortList\n\n        traverseShortList =\n            prismShortList\n                |> Compose.prismWithTraversal Traversal.list\n\n        test_modify_succeeds items =\n            items\n                |> Traversal.modify traverseShortList ((+) 1)\n                |> Expect.equal (items |> List.map ((+) 1))\n\n        test_modify_fails items =\n            items\n                |> Traversal.modify traverseShortList ((+) 1)\n                |> Expect.equal items\n\n        listOfUpToTwoInts =\n            Fuzz.map2\n                (\\maybeX maybeY -> List.filterMap identity [ maybeX, maybeY ])\n                (maybe int)\n                (maybe int)\n\n        listOfThreeOrMoreInts =\n            Fuzz.map4\n                (\\x y z more -> x :: y :: z :: more)\n                int\n                int\n                int\n                (list int)\n    in\n    describe \"Compose.prismWithTraversal\"\n        [ test_modify_succeeds |> fuzz listOfUpToTwoInts \"modify succeeds\"\n        , test_modify_fails |> fuzz listOfThreeOrMoreInts \"modify fails\"\n        ]\n\n\ntest_optionalWithIso : Test\ntest_optionalWithIso =\n    let\n        optionalCity =\n            Optional .city (\\city address -> { address | city = Just city })\n\n        isoReverse =\n            Iso String.reverse String.reverse\n\n        optionalCityReverse =\n            optionalCity\n                |> Compose.optionalWithIso isoReverse\n\n        test_getOption city =\n            { city = Just city }\n                |> .getOption optionalCityReverse\n                |> Expect.equal (Just (city |> String.reverse))\n\n        test_set ( city, newCity ) =\n            { city = Just city }\n                |> .set optionalCityReverse (newCity |> String.reverse)\n                |> Expect.equal { city = Just newCity }\n    in\n    describe \"Compose.optionalWithIso\"\n        [ test_getOption |> fuzz string \".getOption\"\n        , test_set |> fuzz (tuple ( string, string )) \".set\"\n        ]\n\n\ntest_optionalWithLens : Test\ntest_optionalWithLens =\n    let\n        optionalAddress =\n            Optional .address (\\address person -> { person | address = Just address })\n\n        lensStreet =\n            Lens .street (\\street address -> { address | street = street })\n\n        optionalAddressStreet =\n            optionalAddress\n                |> Compose.optionalWithLens lensStreet\n\n        personify ( name, city, street ) =\n            { name = name\n            , address =\n                Just\n                    { city = city\n                    , street = street\n                    }\n            }\n\n        test_getOption ( name, city, street ) =\n            personify ( name, city, street )\n                |> .getOption optionalAddressStreet\n                |> Expect.equal (Just street)\n\n        test_set ( ( name, city, street ), newStreet ) =\n            personify ( name, city, street )\n                |> .set optionalAddressStreet newStreet\n                |> Expect.equal (personify ( name, city, newStreet ))\n    in\n    describe \"Compose.optionalWithLens\"\n        [ test_getOption |> fuzz (tuple3 ( string, string, string )) \".getOption\"\n        , test_set |> fuzz (tuple ( tuple3 ( string, string, string ), string )) \".set\"\n        ]\n\n\ntest_optionalWithOptional : Test\ntest_optionalWithOptional =\n    let\n        optionalAddress =\n            Optional .address (\\address person -> { person | address = Just address })\n\n        optionalStreet =\n            Optional .street (\\street address -> { address | street = Just street })\n\n        optionalAddressStreet =\n            optionalAddress\n                |> Compose.optionalWithOptional optionalStreet\n\n        personify ( name, city, street ) =\n            { name = name\n            , address =\n                Just\n                    { city = city\n                    , street = Just street\n                    }\n            }\n\n        test_getOption ( name, city, street ) =\n            personify ( name, city, street )\n                |> .getOption optionalAddressStreet\n                |> Expect.equal (Just street)\n\n        test_set ( ( name, city, street ), newStreet ) =\n            personify ( name, city, street )\n                |> .set optionalAddressStreet newStreet\n                |> Expect.equal (personify ( name, city, newStreet ))\n    in\n    describe \"Compose.optionalWithOptional\"\n        [ test_getOption |> fuzz (tuple3 ( string, string, string )) \".getOption\"\n        , test_set |> fuzz (tuple ( tuple3 ( string, string, string ), string )) \".set\"\n        ]\n\n\ntest_optionalWithPrism : Test\ntest_optionalWithPrism =\n    let\n        optionalZipCode =\n            Optional .zipcode (\\zipcode address -> { address | zipcode = Just zipcode })\n\n        prismString2Int =\n            Prism String.toInt String.fromInt\n\n        optionalZipCodeString2Int =\n            optionalZipCode\n                |> Compose.optionalWithPrism prismString2Int\n\n        test_getOption zipcode =\n            { zipcode = Just (zipcode |> String.fromInt) }\n                |> .getOption optionalZipCodeString2Int\n                |> Expect.equal (Just zipcode)\n\n        test_set ( zipcode, newZipCode ) =\n            { zipcode = Just (zipcode |> String.fromInt) }\n                |> .set optionalZipCodeString2Int newZipCode\n                |> Expect.equal { zipcode = Just (newZipCode |> String.fromInt) }\n    in\n    describe \"Compose.optionalWithPrism\"\n        [ test_getOption |> fuzz int \".getOption\"\n        , test_set |> fuzz (tuple ( int, int )) \".set\"\n        ]\n\n\ntest_optionalWithTraversal : Test\ntest_optionalWithTraversal =\n    let\n        optionalFriends =\n            Optional .friends (\\friends person -> { person | friends = Just friends })\n\n        traversalFriends =\n            optionalFriends\n                |> Compose.optionalWithTraversal Traversal.list\n\n        test_modify_succeeds friends =\n            { friends = Just friends }\n                |> Traversal.modify traversalFriends String.reverse\n                |> Expect.equal { friends = Just (List.map String.reverse friends) }\n\n        test_modify_fails _ =\n            { friends = Nothing }\n                |> Traversal.modify traversalFriends String.reverse\n                |> Expect.equal { friends = Nothing }\n    in\n    describe \"Compose.optionalWithTraversal\"\n        [ test_modify_succeeds |> fuzz (list string) \"modify succeeds\"\n        , test_modify_fails |> test \"modify fails\"\n        ]\n\n\ntest_traversalWithIso : Test\ntest_traversalWithIso =\n    let\n        isoString2Chars =\n            Iso String.toList String.fromList\n\n        traverseStringsChars =\n            Traversal.list\n                |> Compose.traversalWithIso isoString2Chars\n\n        test_modify_all words =\n            words\n                |> Traversal.modify traverseStringsChars List.reverse\n                |> Expect.equal (List.map String.reverse words)\n    in\n    describe \"Compose.traversalWithIso\"\n        [ test_modify_all |> fuzz (list string) \"modify\"\n        ]\n\n\ntest_traversalWithLens : Test\ntest_traversalWithLens =\n    let\n        lensPersonFirstName =\n            Lens .firstName (\\firstName person -> { person | firstName = firstName })\n\n        traversePeopleFirstNames =\n            Traversal.list\n                |> Compose.traversalWithLens lensPersonFirstName\n\n        test_modify_all people =\n            people\n                |> Traversal.modify traversePeopleFirstNames String.reverse\n                |> Expect.equal (List.map (\\person -> { person | firstName = String.reverse person.firstName }) people)\n\n        randomPerson =\n            Fuzz.map2\n                (\\firstName lastName -> { firstName = firstName, lastName = lastName })\n                string\n                string\n    in\n    describe \"Compose.traversalWithLens\"\n        [ test_modify_all |> fuzz (list randomPerson) \"modify\"\n        ]\n\n\ntest_traversalWithOptional : Test\ntest_traversalWithOptional =\n    let\n        optionalPersonAddress =\n            Optional .address (\\address person -> { person | address = Just address })\n\n        traversePeopleAddresses =\n            Traversal.list\n                |> Compose.traversalWithOptional optionalPersonAddress\n\n        test_modify_all people =\n            people\n                |> Traversal.modify traversePeopleAddresses String.reverse\n                |> Expect.equal (List.map (\\person -> { person | address = Maybe.map String.reverse person.address }) people)\n\n        randomPerson =\n            Fuzz.map2\n                (\\name address -> { name = name, address = address })\n                string\n                (maybe string)\n    in\n    describe \"Compose.traversalWithOptional\"\n        [ test_modify_all |> fuzz (list randomPerson) \"modify\"\n        ]\n\n\ntest_traversalWithPrism : Test\ntest_traversalWithPrism =\n    let\n        prismString2Int =\n            Prism String.toInt String.fromInt\n\n        traverseStringInts =\n            Traversal.list\n                |> Compose.traversalWithPrism prismString2Int\n\n        test_modify_all ints =\n            ints\n                |> List.map String.fromInt\n                |> Traversal.modify traverseStringInts ((+) 1)\n                |> Expect.equal (List.map ((+) 1 >> String.fromInt) ints)\n\n        test_modify_some intValue =\n            [ \"NaN\", String.fromInt intValue ]\n                |> Traversal.modify traverseStringInts ((+) 1)\n                |> Expect.equal [ \"NaN\", String.fromInt (intValue + 1) ]\n    in\n    describe \"Compose.traversalWithPrism\"\n        [ test_modify_all |> fuzz (list int) \"modify all\"\n        , test_modify_some |> fuzz int \"modify some\"\n        ]\n\n\ntest_traversalWithTraversal : Test\ntest_traversalWithTraversal =\n    let\n        traverseListOfList =\n            Traversal.list\n                |> Compose.traversalWithTraversal Traversal.list\n\n        test_modify_all listOfLists =\n            listOfLists\n                |> Traversal.modify traverseListOfList ((+) 1)\n                |> Expect.equal (List.map (List.map ((+) 1)) listOfLists)\n    in\n    describe \"Compose.traversalWithTraversal\"\n        [ test_modify_all |> fuzz (list (list int)) \"modify\"\n        ]\n"
  },
  {
    "path": "tests/IsoSpec.elm",
    "content": "module IsoSpec exposing (..)\n\nimport Test exposing (..)\nimport Expect\nimport Fuzz exposing (list, int, tuple, string, char)\nimport String\nimport Monocle.Iso exposing (Iso)\n\n\nall : Test\nall =\n    describe \"An Iso specification\"\n        [ test_iso_function_get\n        , test_iso_function_reverse_get\n        , test_iso_property_identity\n        , test_iso_property_identity_reversed\n        , test_iso_method_reverse\n        , test_iso_method_modify\n        , test_iso_method_compose\n        ]\n\n\nstring2CharListIso : Iso String (List Char)\nstring2CharListIso =\n    Iso String.toList String.fromList\n\n\ncharList2StringIso : Iso (List Char) String\ncharList2StringIso =\n    Iso String.fromList String.toList\n\n\ntest_iso_function_get : Test\ntest_iso_function_get =\n    let\n        iso =\n            string2CharListIso\n\n        test s =\n            s |> iso.get |> Expect.equal (String.toList s)\n    in\n        fuzz string \"test get function\" test\n\n\ntest_iso_function_reverse_get : Test\ntest_iso_function_reverse_get =\n    let\n        iso =\n            string2CharListIso\n\n        test s =\n            (String.toList s) |> iso.reverseGet |> Expect.equal s\n    in\n        fuzz string \"test reverseGet function\" test\n\n\ntest_iso_property_identity : Test\ntest_iso_property_identity =\n    let\n        iso =\n            string2CharListIso\n\n        test s =\n            s |> iso.get >> iso.reverseGet |> Expect.equal s\n    in\n        fuzz string \"test identity property: reverseGet(get(x)) == x\" test\n\n\ntest_iso_property_identity_reversed : Test\ntest_iso_property_identity_reversed =\n    let\n        iso =\n            charList2StringIso\n\n        test s =\n            s |> iso.reverseGet >> iso.get |> Expect.equal s\n    in\n        fuzz string \"test identity property reversed: get(reverseGet(x)) == x\" test\n\n\ntest_iso_method_reverse : Test\ntest_iso_method_reverse =\n    let\n        iso =\n            string2CharListIso\n\n        isor =\n            Monocle.Iso.reverse iso\n\n        test s =\n            Expect.equal (iso.get s) (isor.reverseGet s)\n    in\n        fuzz string \"test reverse method\" test\n\n\ntest_iso_method_modify : Test\ntest_iso_method_modify =\n    let\n        iso =\n            string2CharListIso\n\n        test s ch =\n            let\n                fx xs =\n                    ch :: xs\n\n                modified =\n                    Monocle.Iso.modify iso fx\n            in\n                modified s |> Expect.equal (String.cons ch s)\n    in\n        fuzz2 string char \"test modify method\" test\n\n\ntest_iso_method_compose : Test\ntest_iso_method_compose =\n    let\n        iso =\n            Monocle.Iso.compose string2CharListIso charList2StringIso\n\n        test s =\n            s |> iso.get |> Expect.equal s\n    in\n        fuzz string \"test compose method\" test\n"
  },
  {
    "path": "tests/LensSpec.elm",
    "content": "module LensSpec exposing (..)\n\nimport Test exposing (..)\nimport Expect\nimport Fuzz exposing (Fuzzer, list, int, string, char)\nimport String\nimport Monocle.Iso exposing (Iso)\nimport Monocle.Prism exposing (Prism)\nimport Monocle.Lens exposing (Lens, compose, modify, modify2, modify3, zip, modifyAndMerge, tuple, tuple3)\nimport Maybe exposing (Maybe)\n\n\nall : Test\nall =\n    describe\n        \"A Lens specification\"\n        [ test_lens_property_identity\n        , test_lens_property_identity_reverse\n        , test_lens_method_compose\n        , test_lens_method_modify\n        , test_lens_method_modify2\n        , test_lens_method_modify3\n        , test_lens_method_zip\n        , test_lens_method_modifyAndMerge\n        , test_lens_method_tuple\n        , test_lens_method_tuple3\n        ]\n\n\ntype StreetType\n    = Street\n    | Avenue\n\n\ntype Country\n    = US\n    | UK\n    | FI\n    | PL\n    | DE\n\n\ntype alias Address =\n    { streetName : String\n    , streetType : StreetType\n    , floor : Maybe Int\n    , town : String\n    , region : Maybe String\n    , postcode : String\n    , country : Country\n    }\n\n\ntype alias Place =\n    { name : String\n    , description : String\n    , address : Address\n    }\n\n\naddressStreetNameLens : Lens Address String\naddressStreetNameLens =\n    let\n        get a =\n            a.streetName\n\n        set sn a =\n            { a | streetName = sn }\n    in\n        Lens get set\n\n\naddressPostcodeLens : Lens Address String\naddressPostcodeLens =\n    let\n        get a =\n            a.postcode\n\n        set p a =\n            { a | postcode = p }\n    in\n        Lens get set\n\n\naddressTownLens : Lens Address String\naddressTownLens =\n    let\n        get a =\n            a.town\n\n        set t a =\n            { a | town = t }\n    in\n        Lens get set\n\n\nplaceAddressLens : Lens Place Address\nplaceAddressLens =\n    let\n        get p =\n            p.address\n\n        set a p =\n            { p | address = a }\n    in\n        Lens get set\n\n\naddresses : Fuzzer Address\naddresses =\n    let\n        address name town postcode =\n            { streetName = name, streetType = Street, floor = Nothing, town = town, region = Nothing, postcode = postcode, country = US }\n    in\n        Fuzz.map3 address string string string\n\n\nplaces : Fuzzer Place\nplaces =\n    Fuzz.map3 Place string string addresses\n\n\ntest_lens_property_identity : Test\ntest_lens_property_identity =\n    let\n        lens =\n            addressStreetNameLens\n\n        test address =\n            lens.set (lens.get address) address |> Expect.equal address\n    in\n        fuzz addresses \"For all a: A, (set (get a) a) == a\" test\n\n\ntest_lens_property_identity_reverse : Test\ntest_lens_property_identity_reverse =\n    let\n        lens =\n            addressStreetNameLens\n\n        test ( street, address ) =\n            lens.get (lens.set street address) |> Expect.equal street\n    in\n        fuzz (Fuzz.tuple ( string, addresses )) \"For all a: A, get (set a a) == a\" test\n\n\ntest_lens_method_compose : Test\ntest_lens_method_compose =\n    let\n        lens =\n            compose placeAddressLens addressStreetNameLens\n\n        test ( street, place ) =\n            lens.get (lens.set street place) |> Expect.equal street\n    in\n        fuzz (Fuzz.tuple ( string, places )) \"Lens compose method\" test\n\n\ntest_lens_method_modify : Test\ntest_lens_method_modify =\n    let\n        fx street =\n            String.reverse street\n\n        lens =\n            compose placeAddressLens addressStreetNameLens\n\n        expected place =\n            lens.set (String.reverse (lens.get place)) place\n\n        test place =\n            place |> (modify lens fx) |> Expect.equal (expected place)\n    in\n        fuzz places \"Lens modify method\" test\n\n\ntest_lens_method_modify2 : Test\ntest_lens_method_modify2 =\n    let\n        fx ( street, postcode ) =\n            ( String.reverse street, String.append \"_\" postcode )\n\n        lens1 =\n            compose placeAddressLens addressStreetNameLens\n\n        lens2 =\n            addressPostcodeLens\n\n        lens3 =\n            addressPostcodeLens\n\n        expected ( place, address ) =\n            ( place |> lens1.set (String.reverse (lens1.get place))\n            , address |> lens2.set (String.append \"_\" (lens2.get address))\n            )\n\n        test x =\n            x |> (modify2 lens1 lens2 fx) |> Expect.equal (expected x)\n    in\n        fuzz (Fuzz.tuple ( places, addresses )) \"Lens modify2 method\" test\n\n\ntest_lens_method_modify3 : Test\ntest_lens_method_modify3 =\n    let\n        fx ( street1, street2, street3 ) =\n            ( street3, street1, street2 )\n\n        lens =\n            compose placeAddressLens addressStreetNameLens\n\n        expected ( place1, place2, place3 ) =\n            ( place1 |> lens.set (lens.get place3)\n            , place2 |> lens.set (lens.get place1)\n            , place3 |> lens.set (lens.get place2)\n            )\n\n        test x =\n            x |> (modify3 lens lens lens fx) |> Expect.equal (expected x)\n    in\n        fuzz (Fuzz.tuple3 ( places, places, places )) \"Lens modify3 method\" test\n\n\ntest_lens_method_zip : Test\ntest_lens_method_zip =\n    let\n        address =\n            Address \"test\" Street Nothing \"test\" Nothing \"test\" US\n\n        place =\n            Place \"test\" \"test\" address\n\n        lens =\n            zip placeAddressLens addressStreetNameLens\n\n        test x =\n            lens.get (lens.set x ( place, address )) |> Expect.equal x\n    in\n        fuzz (Fuzz.tuple ( addresses, string )) \"Lens zip method\" test\n\n\ntest_lens_method_modifyAndMerge : Test\ntest_lens_method_modifyAndMerge =\n    let\n        lens =\n            compose placeAddressLens addressStreetNameLens\n\n        fx a =\n            ( String.reverse a, String.length a )\n\n        merge a b =\n            a + b\n\n        modifiedFx =\n            modifyAndMerge lens fx merge\n\n        expected ( place, n ) =\n            ( (lens.set (String.reverse (lens.get place)) place), n + (String.length (lens.get place)) )\n\n        test p =\n            modifiedFx p |> Expect.equal (expected p)\n    in\n        fuzz (Fuzz.tuple ( places, int )) \"Lens modifyAndMerge method\" test\n\n\ntest_lens_method_tuple : Test\ntest_lens_method_tuple =\n    let\n        lens =\n            tuple addressStreetNameLens addressPostcodeLens\n\n        test ( address, street, postcode ) =\n            lens.get (lens.set ( street, postcode ) address) |> Expect.equal ( street, postcode )\n    in\n        fuzz (Fuzz.tuple3 ( addresses, string, string )) \"Lens tuple method\" test\n\n\ntest_lens_method_tuple3 : Test\ntest_lens_method_tuple3 =\n    let\n        lens =\n            tuple3 addressStreetNameLens addressPostcodeLens addressTownLens\n\n        test ( address, ( street, postcode, town ) ) =\n            lens.get (lens.set ( street, postcode, town ) address) |> Expect.equal ( street, postcode, town )\n    in\n        fuzz (Fuzz.tuple ( addresses, Fuzz.tuple3 ( string, string, string ) )) \"Lens tuple3 method\" test\n"
  },
  {
    "path": "tests/OptionalSpec.elm",
    "content": "module OptionalSpec exposing (..)\n\nimport Test exposing (..)\nimport Expect\nimport Fuzz exposing (Fuzzer, list, int, tuple, string, char)\nimport String\nimport Monocle.Iso exposing (Iso)\nimport Monocle.Prism exposing (Prism)\nimport Monocle.Lens exposing (Lens, fromIso)\nimport Monocle.Optional exposing (Optional, fromPrism, fromLens, compose, composeLens, modifyOption, modify, zip)\nimport Maybe exposing (Maybe)\n\n\nall : Test\nall =\n    describe\n        \"An Optional specification\"\n        [ test_optional_property_identity_when_just\n        , test_optional_property_identity_when_nothing\n        , test_optional_property_reverse_identity\n        , test_optional_method_fromPrism_getOption\n        , test_optional_method_fromPrism_set\n        , test_optional_method_compose\n        , test_optional_method_composeLens\n        , test_lens_method_modifyOption_just\n        , test_lens_method_modify_just\n        , test_lens_method_modifyOption_nothing\n        , test_optional_method_zip\n        , test_optional_method_fromLens\n        ]\n\n\ntype StreetType\n    = Street\n    | Avenue\n\n\ntype Country\n    = US\n    | UK\n    | FI\n    | PL\n    | DE\n\n\ntype alias Address =\n    { streetName : String\n    , streetType : StreetType\n    , floor : Maybe Int\n    , town : String\n    , region : Maybe String\n    , postcode : String\n    , country : Country\n    }\n\n\ntype alias Place =\n    { name : String\n    , description : String\n    , address : Maybe Address\n    }\n\n\naddressRegionOptional : Optional Address String\naddressRegionOptional =\n    let\n        getOption a =\n            a.region\n\n        set r a =\n            { a | region = Just r }\n    in\n        Optional getOption set\n\n\naddressStreetNameLens : Lens Address String\naddressStreetNameLens =\n    let\n        get a =\n            a.streetName\n\n        set sn a =\n            { a | streetName = sn }\n    in\n        Lens get set\n\n\nplaceAddressOptional : Optional Place Address\nplaceAddressOptional =\n    let\n        getOption p =\n            p.address\n\n        set a p =\n            { p | address = Just a }\n    in\n        Optional getOption set\n\n\nstring2IntPrism : Prism String Int\nstring2IntPrism =\n    Prism String.toInt String.fromInt\n\n\nstring2CharListIso : Iso String (List Char)\nstring2CharListIso =\n    Iso String.toList String.fromList\n\n\naddressesWithRegion : Fuzzer Address\naddressesWithRegion =\n    let\n        address name town postcode region =\n            { streetName = name, streetType = Street, floor = Nothing, town = town, region = Just region, postcode = postcode, country = US }\n    in\n        Fuzz.map4 address string string string string\n\n\naddressesWithoutRegion : Fuzzer Address\naddressesWithoutRegion =\n    let\n        address name town postcode =\n            { streetName = name, streetType = Street, floor = Nothing, town = town, region = Nothing, postcode = postcode, country = US }\n    in\n        Fuzz.map3 address string string string\n\n\nplaces : Fuzzer Place\nplaces =\n    Fuzz.map3 Place string string (Fuzz.maybe addressesWithRegion)\n\n\nnumbers : Fuzzer String\nnumbers =\n    Fuzz.map String.fromInt int\n\n\ntest_optional_property_identity_when_just =\n    let\n        opt =\n            addressRegionOptional\n\n        test a =\n            opt.getOption a |> Maybe.map (\\r -> opt.set r a) |> Expect.equal (Just a)\n    in\n        fuzz addressesWithRegion \"For some a: A, getOption a |> Maybe.map (r -> set r a)  == Just a\" test\n\n\ntest_optional_property_identity_when_nothing =\n    let\n        opt =\n            addressRegionOptional\n\n        test a =\n            opt.getOption a |> Maybe.map (\\r -> opt.set r a) |> Expect.equal Nothing\n    in\n        fuzz addressesWithoutRegion \"For some a: A, getOption a |> Maybe.map (r -> set r a)  == Nothing\" test\n\n\ntest_optional_property_reverse_identity =\n    let\n        opt =\n            addressRegionOptional\n\n        test ( a, r ) =\n            opt.set r a |> opt.getOption |> Expect.equal (Just r)\n    in\n        fuzz (Fuzz.tuple ( addressesWithoutRegion, string )) \"For all a: A, set a r |> getOption == Just a\" test\n\n\ntest_optional_method_fromPrism_getOption =\n    let\n        opt =\n            fromPrism string2IntPrism\n\n        expected s =\n            Just (String.toInt s |> Maybe.withDefault 0)\n\n        test s =\n            opt.getOption s |> Expect.equal (expected s)\n    in\n        fuzz numbers \"Optional.fromPrism.getOption\" test\n\n\ntest_optional_method_fromPrism_set =\n    let\n        opt =\n            fromPrism string2IntPrism\n\n        test i =\n            opt.set i \"\" |> Expect.equal (String.fromInt i)\n    in\n        fuzz int \"Optional.fromPrism.set\" test\n\n\ntest_optional_method_compose =\n    let\n        opt =\n            compose addressRegionOptional (fromPrism string2IntPrism)\n\n        computed ( a, i ) =\n            opt.set i a\n\n        expected ( a, i ) =\n            { a | region = Just (String.fromInt i) }\n    in\n        fuzz (Fuzz.tuple ( addressesWithRegion, int )) \"Optional.compose\" (\\s -> Expect.equal (computed s) (expected s))\n\n\ntest_optional_method_composeLens =\n    let\n        opt =\n            composeLens addressRegionOptional (fromIso string2CharListIso)\n\n        computed ( a, cl ) =\n            opt.set cl a\n\n        expected ( a, cl ) =\n            { a | region = Just (String.fromList cl) }\n    in\n        fuzz (Fuzz.tuple ( addressesWithRegion, list char )) \"Optional.composeLens\" (\\s -> Expect.equal (computed s) (expected s))\n\n\ntest_lens_method_modifyOption_just =\n    let\n        f sn =\n            String.reverse sn\n\n        opt =\n            addressRegionOptional\n\n        computed a =\n            modifyOption opt f a\n\n        expected a =\n            opt.getOption a |> Maybe.map String.reverse |> Maybe.map (\\b -> opt.set b a)\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz addressesWithRegion \"Optional.modifyOption for Just a\" test\n\n\ntest_lens_method_modifyOption_nothing =\n    let\n        f sn =\n            String.reverse sn\n\n        opt =\n            addressRegionOptional\n\n        computed a =\n            modifyOption opt f a\n\n        expected a =\n            opt.getOption a |> Maybe.map String.reverse |> Maybe.map (\\b -> opt.set b a)\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz addressesWithoutRegion \"Optional.modifyOption for Nothing\" test\n\n\ntest_lens_method_modify_just =\n    let\n        f sn =\n            String.reverse sn\n\n        opt =\n            addressRegionOptional\n\n        computed a =\n            modify opt f a\n\n        expected a =\n            opt.getOption a |> Maybe.map String.reverse |> Maybe.map (\\b -> opt.set b a) |> Maybe.withDefault a\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz addressesWithRegion \"Optional.modify for Just a\" test\n\n\ntest_optional_method_zip =\n    let\n        address1 =\n            Address \"test\" Street Nothing \"test\" Nothing \"test\" US\n\n        address2 =\n            Address \"test\" Street Nothing \"test\" (Just \"test\") \"test\" US\n\n        opt =\n            zip addressRegionOptional addressRegionOptional\n\n        computed x =\n            opt.getOption (opt.set x ( address1, address2 ))\n\n        expected x =\n            Just x\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz (Fuzz.tuple ( string, string )) \"Optional.zip\" test\n\n\ntest_optional_method_fromLens =\n    let\n        opt =\n            fromLens addressStreetNameLens\n\n        computed ( a, s ) =\n            opt.set s a\n\n        expected ( a, s ) =\n            { a | streetName = s }\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz (Fuzz.tuple ( addressesWithRegion, string )) \"Optional.fromLens\" test\n"
  },
  {
    "path": "tests/PrismSpec.elm",
    "content": "module PrismSpec exposing (..)\n\nimport Test exposing (..)\nimport Expect\nimport Fuzz exposing (Fuzzer, list, int, tuple, string, char)\nimport String\nimport Monocle.Iso exposing (Iso)\nimport Monocle.Prism exposing (Prism)\n\n\nall : Test\nall =\n    describe\n        \"A Prism specification\"\n        [ test_prism_property_partial_round_trip_one_way\n        , test_prism_property_no_round_trip_when_not_matching\n        , test_prism_property_round_trip_other_way\n        , test_prism_method_modify\n        , test_prism_method_modify_option\n        , test_prism_method_compose\n        , test_prism_method_composeIso\n        , test_prism_method_fromIso\n        , test_prism_method_fromIso_reverseGet\n        ]\n\n\nstring2IntPrism : Prism String Int\nstring2IntPrism =\n    Prism String.toInt String.fromInt\n\n\nstring2FloatPrism : Prism String Float\nstring2FloatPrism =\n    Prism String.toFloat String.fromFloat\n\n\nfloat2IntPrism : Prism Float Int\nfloat2IntPrism =\n    let\n        getOption float =\n            let\n                int =\n                    truncate float\n\n                back =\n                    toFloat int\n            in\n                if (float == back) then\n                    Just int\n                else\n                    Nothing\n    in\n        Prism getOption toFloat\n\n\nnumbers : Fuzzer String\nnumbers =\n    Fuzz.map String.fromInt int\n\n\nnotnumbers : Fuzzer String\nnotnumbers =\n    Fuzz.map (\\s -> String.append \"_\" s) string\n\n\nnumbersAndNotNumbers : Fuzzer String\nnumbersAndNotNumbers =\n    Fuzz.frequency [ ( 0.5, numbers ), ( 0.5, notnumbers ) ]\n\n\ntest_prism_property_partial_round_trip_one_way : Test\ntest_prism_property_partial_round_trip_one_way =\n    let\n        prism =\n            string2IntPrism\n\n        test s =\n            s\n                |> prism.getOption\n                |> Maybe.map prism.reverseGet\n                |> Expect.equal (Just s)\n    in\n        fuzz numbers \"For some a: A, getOption a |> Maybe.map reverseGet == Just a\" test\n\n\ntest_prism_property_no_round_trip_when_not_matching : Test\ntest_prism_property_no_round_trip_when_not_matching =\n    let\n        prism =\n            string2IntPrism\n\n        test s =\n            s\n                |> prism.getOption\n                |> Maybe.map prism.reverseGet\n                |> Expect.equal Nothing\n    in\n        fuzz notnumbers \"For some a: A, getOption a |> Maybe.map reverseGet == Nothing \" test\n\n\ntest_prism_property_round_trip_other_way : Test\ntest_prism_property_round_trip_other_way =\n    let\n        prism =\n            string2IntPrism\n\n        test i =\n            i\n                |> prism.reverseGet\n                >> prism.getOption\n                |> Expect.equal (Just i)\n    in\n        fuzz int \"For all a: A, getOption (reverseGet a) == Just a \" test\n\n\ntest_prism_method_modify : Test\ntest_prism_method_modify =\n    let\n        prism =\n            string2IntPrism\n\n        computed s =\n            let\n                fx i =\n                    i * 2\n\n                modified =\n                    Monocle.Prism.modify prism fx\n            in\n                modified s\n\n        expected s =\n            s |> String.toInt >> Maybe.map ((*) 2 >> String.fromInt) |> Maybe.withDefault s\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz string \"Prism method modify\" test\n\n\ntest_prism_method_modify_option : Test\ntest_prism_method_modify_option =\n    let\n        prism =\n            string2IntPrism\n\n        computed s =\n            let\n                fx i =\n                    i * 2\n\n                modified =\n                    Monocle.Prism.modifyOption prism fx\n            in\n                modified s\n\n        expected s =\n            s |> String.toInt >> Maybe.map ((*) 2 >> String.fromInt)\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz numbersAndNotNumbers \"Prism method modifyOption\" test\n\n\ntest_prism_method_compose : Test\ntest_prism_method_compose =\n    let\n        iso =\n            Iso ((*) 10) ((//) 10)\n\n        prism =\n            Monocle.Prism.composeIso string2IntPrism iso\n\n        computed s =\n            prism.getOption s\n\n        expected s =\n            s |> String.toInt >> Maybe.map ((*) 10)\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz numbersAndNotNumbers \"Prism method compose\" test\n\n\ntest_prism_method_composeIso : Test\ntest_prism_method_composeIso =\n    let\n        iso =\n            Iso ((*) 10) ((//) 10)\n\n        prism =\n            Monocle.Prism.composeIso string2IntPrism iso\n\n        computed s =\n            prism.getOption s\n\n        expected s =\n            s |> String.toInt >> Maybe.map ((*) 10)\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz numbersAndNotNumbers \"Prism method composeIso\" test\n\n\ntest_prism_method_fromIso : Test\ntest_prism_method_fromIso =\n    let\n        iso =\n            Iso String.toList String.fromList\n\n        prism =\n            Monocle.Prism.fromIso iso\n\n        computed s =\n            prism.getOption s\n\n        expected s =\n            iso.get s |> Just\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz string \"Prism method fromIso\" test\n\n\ntest_prism_method_fromIso_reverseGet : Test\ntest_prism_method_fromIso_reverseGet =\n    let\n        iso =\n            Iso String.fromList String.toList\n\n        prism =\n            Monocle.Prism.fromIso iso\n\n        computed s =\n            prism.reverseGet s\n\n        expected s =\n            iso.reverseGet s\n\n        test s =\n            Expect.equal (computed s) (expected s)\n    in\n        fuzz string \"Prism method fromIso when reverseGet\" test\n"
  },
  {
    "path": "tests/Tests.elm",
    "content": "module Tests exposing (..)\n\nimport Test exposing (..)\nimport Expect\nimport Fuzz exposing (list, int, tuple, string)\nimport String\nimport IsoSpec\nimport PrismSpec\nimport LensSpec\nimport OptionalSpec\nimport CommonSpec\n\n\nall : Test\nall =\n    describe \"Elm Monocle specification\"\n        [ IsoSpec.all\n        , PrismSpec.all\n        , LensSpec.all\n        , OptionalSpec.all\n        , CommonSpec.all\n        ]\n"
  },
  {
    "path": "tests/TraversalSpec.elm",
    "content": "module TraversalSpec exposing (all)\n\nimport Array\nimport Expect\nimport Fuzz exposing (array, int, list)\nimport Monocle.Traversal as Traversal\nimport Test exposing (..)\n\n\nall : Test\nall =\n    describe\n        \"A Traversal specification\"\n        [ test_list_traversal\n        , test_array_traversal\n        , test_some_traversal\n        ]\n\n\ntest_list_traversal : Test\ntest_list_traversal =\n    let\n        test s =\n            s\n                |> Traversal.modify Traversal.list ((*) 2)\n                |> Expect.equal (List.map ((*) 2) s)\n    in\n    fuzz (list int) \"Traversal modify on a list\" test\n\n\ntest_array_traversal : Test\ntest_array_traversal =\n    let\n        test s =\n            s\n                |> Traversal.modify Traversal.array ((*) 2)\n                |> Expect.equal (Array.map ((*) 2) s)\n    in\n    fuzz (array int) \"Traversal modify on an array\" test\n\n\ntest_some_traversal : Test\ntest_some_traversal =\n    let\n        odds =\n            Traversal.some Traversal.list (\\n -> remainderBy 2 n == 1)\n\n        test _ =\n            [ 1, 2, 3, 4, 5 ]\n                |> Traversal.modify odds ((+) 3)\n                |> Expect.equal [ 4, 2, 6, 4, 8 ]\n    in\n    Test.test \"Traversal modify some elements in an array\" test\n"
  }
]