Skip to content

Commit dba831a

Browse files
Fill out additional docs on things (#28)
1 parent 942b5b4 commit dba831a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ New features:
1111
Bugfixes:
1212

1313
Other improvements:
14+
- Documented additional things (#28 by @JordanMartinez)
15+
- `These` data type and a short description of how type class instances work
16+
- `these` and `fromThese` functions
1417

1518
## [0.0.0] - 2020-01-01

src/Data/These.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Data.Maybe (Maybe(..), isJust)
1010
import Data.Traversable (class Traversable, class Foldable, foldMap, foldl, foldr)
1111
import Data.Tuple (Tuple(..))
1212

13+
-- | Data type isomorphic to `α ∨ β ∨ (α ∧ β)` or
14+
-- | `Either a (Either b (Tuple a b))`.
1315
data These a b
1416
= This a
1517
| That b
@@ -98,6 +100,8 @@ instance showThese :: (Show a, Show b) => Show (These a b) where
98100
show (That y) = "(That " <> show y <> ")"
99101
show (Both x y) = "(Both " <> show x <> " " <> show y <> ")"
100102

103+
-- | Given functions to handle each constructor, collapse a `These` value
104+
-- | into single value.
101105
these :: forall a b c. (a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> c
102106
these l _ _ (This a) = l a
103107
these _ r _ (That x) = r x
@@ -119,6 +123,10 @@ maybeThese = case _, _ of
119123
Just a, Just b -> Just (Both a b)
120124
Nothing, Nothing -> Nothing
121125

126+
-- | Takes two default values and a `These` value. If the `These` value is
127+
-- | `This` or `That`, the value wrapped in the `These` value and its
128+
-- | corresponding default value are wrapped into a `Tuple`.
129+
-- | Otherwise, the values stored in the `Both` are rewrapped into a `Tuple`.
122130
fromThese :: forall a b. a -> b -> These a b -> Tuple a b
123131
fromThese _ x (This a) = Tuple a x
124132
fromThese a _ (That x) = Tuple a x

0 commit comments

Comments
 (0)