{"id":23902812,"url":"https://github.com/mtumilowicz/java11-vavr093-option-workshop","last_synced_at":"2026-07-22T03:01:58.262Z","repository":{"id":110877533,"uuid":"173505448","full_name":"mtumilowicz/java11-vavr093-option-workshop","owner":"mtumilowicz","description":"Vavr Option workshop.","archived":false,"fork":false,"pushed_at":"2019-07-28T08:31:05.000Z","size":136,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T12:54:49.367Z","etag":null,"topics":["option","vavr","vavr-option","workshop","workshop-materials","workshops"],"latest_commit_sha":null,"homepage":"","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtumilowicz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-03-02T22:23:50.000Z","updated_at":"2020-02-15T19:23:25.000Z","dependencies_parsed_at":"2024-02-23T02:30:27.909Z","dependency_job_id":null,"html_url":"https://github.com/mtumilowicz/java11-vavr093-option-workshop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mtumilowicz/java11-vavr093-option-workshop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-vavr093-option-workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-vavr093-option-workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-vavr093-option-workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-vavr093-option-workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtumilowicz","download_url":"https://codeload.github.com/mtumilowicz/java11-vavr093-option-workshop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava11-vavr093-option-workshop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261162066,"owners_count":23118221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["option","vavr","vavr-option","workshop","workshop-materials","workshops"],"created_at":"2025-01-04T22:50:41.221Z","updated_at":"2025-10-13T08:17:32.718Z","avatar_url":"https://github.com/mtumilowicz.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/mtumilowicz/java11-vavr093-option-workshop.svg?branch=master)](https://travis-ci.com/mtumilowicz/java11-vavr093-option-workshop)\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n\n# java11-vavr093-option-workshop\n\n# project description\n* https://www.vavr.io/vavr-docs/#_option\n* https://static.javadoc.io/io.vavr/vavr/0.9.3/io/vavr/control/Option.html\n* https://github.com/mtumilowicz/java11-vavr-option\n* https://github.com/mtumilowicz/java11-category-theory-optional-is-not-functor\n* in the workshop we will try to fix failing tests `test/groovy/Workshop`\n* answers: `test/groovy/Answers` (same tests as in `Workshop` but correctly solved)\n\n# theory in a nutshell\n* similar to `Optional`, but with bigger, more flexible API\n* `interface Option\u003cT\u003e extends Value\u003cT\u003e, Serializable`\n    * `interface Value\u003cT\u003e extends Iterable\u003cT\u003e`\n* `Option` is isomorphic to singleton list (either has element or not, so it could be treated as collection)\n* two implementations:\n    * `final class Some\u003cT\u003e`\n    * `final class None\u003cT\u003e`\n* `None` instance is a singleton\n* returning `null` inside `map` does not cause `Option` switch to `None` (contrary to `Optional`)\n    ```\n    expect:\n    Option.some(2).map(alwaysNull).defined\n    Optional.of(2).map(alwaysNull).empty\n    ```\n* it is possible to have `Some(null)`, so `NPE` is possible even on defined `Option`\n* excellent for modelling exists / not exists (Spring Data - `findById`)\n    * not every \"exceptional\" behaviour could be modelled as exists / not exists\n    \n# conclusions in a nutshell\n* **we omit methods that `Optional` has**\n* easy conversion `Option\u003cT\u003e` \u003c-\u003e `Optional\u003cT\u003e`\n    * `Option.ofOptional`\n    * `option.toJavaOptional()`\n* handy conversion `List\u003cOption\u003cT\u003e\u003e -\u003e Option\u003cList\u003cT\u003e\u003e`\n    * `Option.sequence(list)`\n    * if any of the `Options` are `None` - returns `None`\n* conditional supplier\n    * `static Option\u003cT\u003e when(boolean condition, Supplier\u003c? extends T\u003e supplier)`\n* mapping with the partial function\n    * `Option\u003cR\u003e collect(PartialFunction\u003c? super T, ? extends R\u003e partialFunction)`\n    * if function is not defined for the value - returns `None`\n* side effects on `None`\n    * `Option\u003cT\u003e onEmpty(Runnable action)`\n* side effects on `Some`\n    * `Option\u003cT\u003e peek(Consumer\u003c? super T\u003e action)`\n* lazy alternative (in `Optional` since 11)\n    * `Option\u003cT\u003e orElse(Supplier\u003c? extends Option\u003c? extends T\u003e\u003e supplier)`\n* `transform` function could be nearly always replaced with more expressive and natural `map(...).orElse(...)`\n    ```\n    given:\n    Function\u003cOption\u003cInteger\u003e, String\u003e transformer = { it.isEmpty() ? '' : it.get().toString() }\n    expect:\n    Option.of(5).transform(transformer) == '5'\n    ```\n    same as\n    ```\n    given:\n    Function\u003cOption\u003cInteger\u003e, String\u003e transformer = { it.isEmpty() ? '' : it.get().toString() }\n    expect:\n    transformerFive = Option.of(5)\n        .map { it.toString() }\n        .orElse('') == '5'\n    ```\n* conversion `Option\u003cT\u003e` \u003c-\u003e `List\u003cT\u003e`\n    * `option.toList()`\n    * `list.toOption()`\n* could be treated as collection\n    * `boolean contains(T element)`\n    * `boolean exists(Predicate\u003c? super T\u003e predicate)`\n    * `boolean forAll(Predicate\u003c? super T\u003e predicate)`\n* well written equals\n    * `Some`\n        ```\n        return (obj == this) || (obj instanceof Some \u0026\u0026 Objects.equals(value, ((Some\u003c?\u003e) obj).value));\n        ```\n    * `None`\n        ```\n        return o == this\n        ```\n* map does not breaks monadic laws\n    ```\n    given:\n    Function\u003cInteger, Integer\u003e alwaysNull = { null }\n    Function\u003cInteger, String\u003e safeToString = { nonNull(it) ? String.valueOf(it) : 'null' }\n    Function\u003cInteger, String\u003e composition = alwaysNull.andThen(safeToString)\n    \n    expect:\n    Optional.of(1).map(composition) != Optional.of(1).map(alwaysNull).map(safeToString)\n    Optional.of(1).stream().map(composition).findAny() == Optional.of(1).stream()\n            .map(alwaysNull)\n            .map(safeToString)\n            .findAny()\n    Option.of(1).map(composition) == Option.of(1).map(alwaysNull).map(safeToString)\n    ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fjava11-vavr093-option-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtumilowicz%2Fjava11-vavr093-option-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fjava11-vavr093-option-workshop/lists"}