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

Add Last Documentation #197

Merged
merged 3 commits into from
Feb 4, 2018
Merged

Add Last Documentation #197

merged 3 commits into from
Feb 4, 2018

Conversation

evilsoft
Copy link
Owner

Last but not Least

image

This is another PR that addresses the Last item on this issue by adding the README for the Last monoid. It is pretty much the same thing as First, but kinda the opposite.

Also made some corrections to the First README in this PR as well.

@coveralls
Copy link

coveralls commented Jan 31, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 5018c2a on last-docs into 60a482b on master.

@evilsoft evilsoft changed the title Add Last Documentation Add Last Documentation Jan 31, 2018
`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`.
Copy link

@foxdonut foxdonut Jan 31, 2018

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.

Copy link

@foxdonut foxdonut left a 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!


`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

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?

const mconcatMap = require('crocks/helpers/mconcatMap')
const safe = require('crocks/Maybe/safe')

// lastString :: [ a ] -> Last String

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

const firstString =
mconcatMap(First, safe(isString))

// unfixFirstString :: [ a ] -> First String

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


unfixFirstString([ 'one', 2, 'Three', 4 ])
.concat(Last('another string'))
//=> Last( Just "another string" )

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" )


lastNumVal({ val: 97 })
.concat(Last(80))
//=> Last( Just 97 )

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.

Copy link
Owner Author

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 )


// isEven :: Number -> Boolean
const isEven =
x => !(x % 2)
Copy link
Contributor

@rpearce rpearce Feb 4, 2018

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 ¯\(ツ)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good call.
🔧-ing

Copy link
Contributor

Choose a reason for hiding this comment

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

ty ❤️

@evilsoft
Copy link
Owner Author

evilsoft commented Feb 4, 2018

image

@evilsoft evilsoft merged commit 4ad2228 into master Feb 4, 2018
@evilsoft evilsoft deleted the last-docs branch February 4, 2018 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants