-
Notifications
You must be signed in to change notification settings - Fork 11
Option #7
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
base: main
Are you sure you want to change the base?
Option #7
Conversation
Codecov Report
@@ Coverage Diff @@
## main #7 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 11 11
Lines 119 139 +20
=========================================
+ Hits 119 139 +20
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
The last commit should fix the issue #8 |
Also implemented the |
hello @Force4760, thanks again, couple inline comments:
I have some doubts on this if it's something inline with functional principles as the end result might be changed by some external code changing the value the pointer is pointing to. Do you have further examples of something similar in Scala or fp-ts? Would be really useful to understand how that could be used in the future.
i think we should rename it as
LGTM we might also check fp-ts for ref
LGTM i would just split the implementation in another PR and rename it as
On the I will keep the PR open to discuss the various points but would be great to separate in other smaller PRs code that it's ok to be merged. |
PointersI haven't seen anything similar neither in fp-ts nor scala (I don't think TS has pointers) Pointers are, in some way, an unsafe version of option
The idea behind Even if we want to keep everything pure, some other important/popular go modules use pointers, so it would be needed to have some kind of bridge between options and pointers. GetThe use of func ZipWith(f func(A, B) C, oA Option[A], oB Option[B]) Option[C] {
if isSome(oA) && isSome(oB) {
// Because of the `if statement` we are sure that `Get` will not panic
return Some( f( Get(oA), Get(oB) )
}
return None[C]
} Name changesNo problem at all :) |
Improve the Option implementation by adding the following functions:
FromPtr
: Lifts a pointer into an OptionToPtr
: "Unlifts" an Option into a pointerIsSomeAnd
: Check if the Option has a value and if that value satisfies a predicateFilter
: Apply a predicate to the Option value if it exists and return Some on true and None on falseFlat
: Remove one level of nesting from an Option:Option[Option[T]] -> Option[T]
I also added tests for these new features and a mention in the Readme