Skip to content
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

DynComms [0/n]: fn package additions #8653

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ProofOfKeags
Copy link
Collaborator

@ProofOfKeags ProofOfKeags commented Apr 15, 2024

NOTE: This change is part of a series implementing Dynamic Commitments.

Change Description

This adds some useful library functions that will allow us to capture patterns we often use throughout the codebase. None of the code in this PR has any direct bearing on Dynamic Commitments but it is generally useful infrastructure that will be assumed to be available in future PRs in the series.

Steps to Test

N/A

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Copy link

coderabbitai bot commented Apr 15, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ProofOfKeags ProofOfKeags requested review from a team, yyforyongyu and morehouse and removed request for a team April 15, 2024 20:54
@ProofOfKeags ProofOfKeags self-assigned this Apr 16, 2024
@ProofOfKeags ProofOfKeags added fn llm-review add to a PR to have an LLM bot review it labels Apr 16, 2024
@ProofOfKeags ProofOfKeags requested review from ziggie1984 and removed request for morehouse April 17, 2024 19:04
@ProofOfKeags ProofOfKeags force-pushed the fn-prim branch 2 times, most recently from 464abe1 to 22b714d Compare April 17, 2024 20:18
@ProofOfKeags ProofOfKeags changed the title Add fn tools DynComms [0/n]: fn package additions Apr 17, 2024
Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I wonder where you get the inspiration for these library functions, these functions are almost suitable for a general golang library using generics ?

fn/fn.go Outdated Show resolved Hide resolved
@@ -136,3 +138,48 @@ func TestZipWith(t *testing.T) {
z, []bool{false, true, false, false, false},
))
}

func TestPropForEachConcMapIsomorphism(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the TestProp prefix makes sense to be generalized in our docs, as soon as we do prop testing ? So we have a consistent way throughout the codebase ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree. Our prop testing is pretty sparse at the moment but it's my preferred form of testing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sounds good, will also create property tests next time, they seem to include also the fuzzing component by creating a whole range of input values.

Maybe we can come up with a nice doc guide in the near future what we expect in general from unit tests in the LND codebase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah what's also nice about them is that it forces you to think more clearly about what the precise requirements of the system are, as opposed to eyeballing a few test cases and hoping that those cases are enough to make reasonable implementations likely. It's a brittle assumption.

fn/slice_test.go Show resolved Hide resolved
foundIdx := FindIdx(pred, s)

// onlyVal :: Option[T2[A, B]] -> Option[B]
onlyVal := MapOption(func(t2 T2[int, uint8]) uint8 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if it makes sense to generalize it ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generalize what?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping a tuple to an Option Tuple to a value: [T2[A, B]] -> Option[T2[A, B]] -> Option[B], could be part of the tuple definition ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should be. However, I do think that maybe exporting functions for Fst and Snd is a good idea.

fn/either.go Show resolved Hide resolved
@ProofOfKeags
Copy link
Collaborator Author

I wonder where you get the inspiration for these library functions, these functions are almost suitable for a general golang library using generics ?

Years of writing Haskell as my native language. Yeah this would be better suited for a golang general lib but I have no desire to do ongoing maintenance of go libraries for the whole golang ecosystem. Further, @Roasbeef doesn't want to depend on external libraries for this kind of thing due to OSS maintainer risk (either malice or just disappearing), which is why we invented the fn package in the first place.

Generally speaking, the fn package is not Bitcoin/Lightning specific in any way. We only want to put stuff in here that is genuinely generic for all sorts or problem domains.

fn/either.go Show resolved Hide resolved

func TestPropConstructorEliminatorDuality(t *testing.T) {
f := func(i int, s string, isRight bool) bool {
Len := func(s string) int { return len(s) } // smh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: what does the comment mean smh ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Shake my head", means disappointment. I was making some commentary about how I couldn't just put len in the field as the type func(string) int even though it would be a sensible thing to be able to do. append has similar issues. Perhaps I should either remove the snarky comment or be more explicit about warning people not to try and refactor it away.

fn/either_test.go Show resolved Hide resolved
@@ -136,3 +138,48 @@ func TestZipWith(t *testing.T) {
z, []bool{false, true, false, false, false},
))
}

func TestPropForEachConcMapIsomorphism(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sounds good, will also create property tests next time, they seem to include also the fuzzing component by creating a whole range of input values.

Maybe we can come up with a nice doc guide in the near future what we expect in general from unit tests in the LND codebase.

foundIdx := FindIdx(pred, s)

// onlyVal :: Option[T2[A, B]] -> Option[B]
onlyVal := MapOption(func(t2 T2[int, uint8]) uint8 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping a tuple to an Option Tuple to a value: [T2[A, B]] -> Option[T2[A, B]] -> Option[B], could be part of the tuple definition ?

fn/either.go Show resolved Hide resolved
@lightninglabs-deploy
Copy link

@ProofOfKeags, remember to re-request review from reviewers when ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants