-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add Last
Documentation
#197
Conversation
src/Last/README.md
Outdated
`Last` is a `Monoid` that will always return the last, non-empty value when | ||
(2) `Last` instances are combined. `Last` is able to be a `Monoid` because | ||
it implements a `Maybe` under the hood. The use of the `Maybe` allows for an | ||
[`empty`][#empty] `Last` to be represented with a `Nothing`. |
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.
[`empty`][#empty] should be [`empty`](#empty)
Note that this is also in First/README.md
.
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.
This is fantastic work @evilsoft keep it up, much appreciated!
src/Last/README.md
Outdated
|
||
`concat` is used to combine (2) `Semigroup`s of the same type under an operation | ||
specified by the `Semigroup`. In the case of `Last`, it will always provide the | ||
last non-empty value. Any subsequent non-empty values will be thrown away and |
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.
Any subsequent non-empty values will be thrown away
Won't subsequent non-empty values actually be kept, so that the last non-empty value will always be the result?
src/Last/README.md
Outdated
const mconcatMap = require('crocks/helpers/mconcatMap') | ||
const safe = require('crocks/Maybe/safe') | ||
|
||
// lastString :: [ a ] -> Last String |
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.
// lastString :: [ a ] -> Last String
should be
// firstString :: [ a ] -> First String
src/Last/README.md
Outdated
const firstString = | ||
mconcatMap(First, safe(isString)) | ||
|
||
// unfixFirstString :: [ a ] -> First String |
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.
// unfixFirstString :: [ a ] -> First String
should be
// unfixFirstString :: [ a ] -> Last String
src/Last/README.md
Outdated
|
||
unfixFirstString([ 'one', 2, 'Three', 4 ]) | ||
.concat(Last('another string')) | ||
//=> Last( Just "another string" ) |
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.
Perhaps also show:
unfixFirstString([ 'one', 2, 'Three', 4 ])
//=> Last( Just "one" )
src/Last/README.md
Outdated
|
||
lastNumVal({ val: 97 }) | ||
.concat(Last(80)) | ||
//=> Last( Just 97 ) |
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.
Not sure what this example is supposed to be, but the result is incorrect. The following example is exactly the same but has the correct result.
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.
That should have been switched to:
Last(Just(80))
.concat(lastNumVal({ val: 97 }))
//=> Last( Just 97 )
src/Last/README.md
Outdated
|
||
// isEven :: Number -> Boolean | ||
const isEven = | ||
x => !(x % 2) |
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.
While this is a clever way to exploit truthy/falsy values of numbers like0
, IMO this could detract from the example because of the boolean thinking required. x % 2 === 0
is usually enough for me. It's not a big deal, though I found myself trying to work out this function instead of the example. Probably because I'm tired, but ¯\(ツ)/¯
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 call.
🔧-ing
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.
ty ❤️
Last but not Least
This is another PR that addresses the
Last
item on this issue by adding the README for theLast
monoid. It is pretty much the same thing asFirst
, but kinda the opposite.Also made some corrections to the
First
README in this PR as well.