-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/overhaul lists #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
51aa69e
1. List overhaul
dan323 4be1819
zip cons
dan323 ebb7e8f
sonar
dan323 97e02fb
sonar
dan323 0d692be
cycled lists
dan323 6011493
Update docs/CORE_CONCEPTS.md
dan323 04ef4db
Update CHANGELOG.md
dan323 17355af
cycled lists
dan323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Core Concepts | ||
|
|
||
| ## Introduction | ||
| This project leverages Java annotations to define and implement functional and algebraic structures. It enables a declarative approach to programming, making code more modular, composable, and easier to reason about. | ||
|
|
||
| ## Functional Structures | ||
| Functional structures are abstractions that allow operations on data in a context. Common examples include: | ||
| - **Functor**: Enables mapping functions over values in a context. | ||
| - **Applicative**: Allows applying functions wrapped in a context to values in a context. | ||
| - **Monad**: Supports chaining computations in a context. | ||
| - **Foldable**: Reduces structures to a single value. | ||
| - **Traversal**: Maps with effects across structures. | ||
| - **Alternative**: Provides choice operations. | ||
|
|
||
| ## Algebraic Structures | ||
| Algebraic structures define mathematical operations and laws: | ||
| - **Semigroup**: Associative operation (`op`). | ||
| - **Monoid**: Semigroup with an identity element (`unit`). | ||
| - **Ring**: Supports addition and multiplication operations. | ||
|
|
||
| ## Annotations | ||
| Annotations such as `@Functor`, `@Monad`, `@Semigroup`, etc., are used to mark types and specify minimal required methods. The annotation processor generates boilerplate code and validates that the required methods are present. | ||
|
|
||
| ## Type Hierarchy and Structure | ||
| Types are organized hierarchically, with interfaces like `Algebraic` and `Structure` serving as base types. Each structure requires minimal implementations (e.g., `map` for Functor, `op` for Semigroup). | ||
|
|
||
| ## Minimal Implementations | ||
| Each annotation specifies the minimal set of methods required. For example: | ||
| - `@Functor`: Requires `map`. | ||
| - `@Monoid`: Requires `op` and `unit`. | ||
| - `@Ring`: Requires both addition and multiplication operations. | ||
|
|
||
| ## Type Constructors and Variance | ||
| The library supports generic types and type constructors, enabling flexible and reusable abstractions. | ||
|
|
||
| --- | ||
| For more details, see [Functional Structures](FUNCTIONAL_STRUCTURES.md) and [Algebraic Structures](ALGEBRAIC_STRUCTURES.md). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
example-functional/src/main/java/com/dan323/functional/data/list/Cycle.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.dan323.functional.data.list; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
| public final class Cycle<A> extends InfiniteList<A> { | ||
|
|
||
| private final FiniteList<A> cycled; | ||
|
|
||
| Cycle(FiniteList<A> cycle) { | ||
| if (cycle == null || cycle.length() == 0) { | ||
| throw new IllegalArgumentException("The list to be cycled must not be null or empty."); | ||
| } | ||
| this.cycled = cycle; | ||
| } | ||
|
|
||
| @Override | ||
| public A getHead() { | ||
| return cycled.head().maybe(Function.identity(), null); | ||
| } | ||
|
|
||
| @Override | ||
| public InfiniteList<A> tail() { | ||
| var init = cycled.tail(); | ||
| return ListUtils.concat(init, this); | ||
| } | ||
|
|
||
| @Override | ||
| public <B> Cycle<B> map(Function<A, B> mapping) { | ||
| return new Cycle<>(cycled.map(mapping)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 17 additions & 3 deletions
20
example-functional/src/main/java/com/dan323/functional/data/list/InfiniteList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.