Skip to content

Conversation

@asciola
Copy link

@asciola asciola commented Nov 7, 2014

Adding monoid & group for arrays.

The monoid takes the provided arrays and does pair-wise addition of the elements. If one array is longer than the other, the result is longer.size in length with the items from the longer copied over. zero returns an empty Array.

The group extends the monoid and implements negation by calling negate on the individual items of the array.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add tests using monoidLaws and groupLaws for commutative and non-commutative cases? An example non-commutative monoid would be String (I am not sure we actually have any non-commutative groups implemented, but for fun you could do quaternions).

@johnynek
Copy link
Collaborator

Here is an example:

https://github.com/twitter/algebird/blob/develop/algebird-test/src/test/scala/com/twitter/algebird/JavaBoxedTests.scala#L68

You should always have two kinds of tests: 1) show the logic works as you claim it does (in this case like .zip with padding then pointwise addition). 2) that the monoid/group/ring laws are satisfied. Part 2 is already done for you, you just need to call the correct methods.

Added a monoidLaws test.
johnynek added a commit that referenced this pull request Nov 20, 2014
Add Array Monoid & Group.
@johnynek johnynek merged commit 23fd664 into twitter:develop Nov 20, 2014
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.

2 participants