-
Notifications
You must be signed in to change notification settings - Fork 10
Fill out additional docs on things #28
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
thomashoneyman
merged 9 commits into
purescript-contrib:main
from
JordanMartinez:addDocs
Sep 14, 2020
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
455487b
Clarify These type and what most type class instances operate on
JordanMartinez 11fbaac
Document the `these` function
JordanMartinez c015b27
Document the `fromThese` function
JordanMartinez 52d443e
Update changelog with PR's content
JordanMartinez 24fff5e
Include author name in PR
JordanMartinez e507767
Reword the `fromThese` documentation
JordanMartinez 9369b0c
Update docs for `these`
JordanMartinez e1e3213
Remove doc explaining that most TC instances work on the `b` type
JordanMartinez 527ecd8
Fix grammatical mistake
JordanMartinez 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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,6 +10,10 @@ import Data.Maybe (Maybe(..), isJust) | |||||||||
import Data.Traversable (class Traversable, class Foldable, foldMap, foldl, foldr) | ||||||||||
import Data.Tuple (Tuple(..)) | ||||||||||
|
||||||||||
-- | Data type isomorphic to `α ∨ β ∨ (α ∧ β)` or | ||||||||||
-- | `Either a (Either b (Tuple a b))`. | ||||||||||
-- | | ||||||||||
-- | Most type classes instances work on the value of the `b` type. | ||||||||||
data These a b | ||||||||||
= This a | ||||||||||
| That b | ||||||||||
|
@@ -98,6 +102,8 @@ instance showThese :: (Show a, Show b) => Show (These a b) where | |||||||||
show (That y) = "(That " <> show y <> ")" | ||||||||||
show (Both x y) = "(Both " <> show x <> " " <> show y <> ")" | ||||||||||
|
||||||||||
-- | Given functions to handle each constructor, collapse a `These` value | ||||||||||
-- | into single value. | ||||||||||
these :: forall a b c. (a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> c | ||||||||||
these l _ _ (This a) = l a | ||||||||||
these _ r _ (That x) = r x | ||||||||||
|
@@ -119,6 +125,10 @@ maybeThese = case _, _ of | |||||||||
Just a, Just b -> Just (Both a b) | ||||||||||
Nothing, Nothing -> Nothing | ||||||||||
|
||||||||||
-- | Takes two default values and a `These` value. If the `These` value is | ||||||||||
-- | `This` or `That`, the value wrapped in the `These` value and its | ||||||||||
-- | corresponding default value are wrapped into a `Tuple`. | ||||||||||
-- | Otherwise, the values stored in the `Both` is rewrapped into a `Tuple`. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Minor typo here ("values" -> "are") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||||||
fromThese :: forall a b. a -> b -> These a b -> Tuple a b | ||||||||||
fromThese _ x (This a) = Tuple a x | ||||||||||
fromThese a _ (That x) = Tuple a x | ||||||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this line is needed, as this is the same
Functor
behavior that applies to any type with multiple type arguments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line should become the new precedent because its helpful for new learners. However, I don't believe strongly in this either. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not to include it -- it's more important that new learners are able to associate this structure with
Functor
(orBifunctor
). For new learners I would rather have a brief example of usingmap
with aThese
value in the quick start so they can begin to recognize a very wide-ranging pattern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Fixed