Skip to content

Add READMEs for All, Any and Arrow types #148

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
merged 3 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions src/All/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# All
```haskell
All Boolean
```
`All` is a `Monoid` that will combine two values of any type using logical conjunction (AND) on their coerced `Boolean` values, mapping truth-y values to `true` and false-y values to `false`.

```js
const All = require('crocks/All')
const mconcat = require('crocks/helpers/mconcat')

const trueNum = All(13)
const falseNum = All(0)
const trueString = All('So true')

trueNum.concat(falseNum)
//=> All false

trueNum.concat(trueString)
//=> All true

const allGood =
mconcat(All)

allGood([ 1, 5, 89 ])
//=> All true

allGood([ 'nice', '00', null ])
//=> All false
```

## Implements
`Semigroup`, `Monoid`

## Constructor Methods

### empty
```haskell
All.empty :: () -> All
```

`empty` provides the identity for the `Monoid` in that when the value it provides is `concat`ed to any other value, it will return the other value. In the case of `All` the result of `empty` is `true`. `empty` is available on both the Constructor and the Instance for convenience.
```js
All.empty() //=> All true

All(true).concat(All.empty()) //=> All true
All(false).concat(All.empty()) //=> All false
```


### type
```haskell
All.type :: () -> String
```

`type` provides a string representation of the type name for a given type in `crocks`. While it is used mostly internally for law validation, it can be useful to the end user for debugging and building out custom types based on the standard `crocks` types. While type comparisons can easily be done manually by calling `type` on a given type, using the `isSameType` function hides much of the boilerplate. `type` is available on both the Constructor and the Instance for convenience.

```js
const Maybe = require('crocks/Maybe')
const isSameType = require('crocks/predicates/isSameType')

All.type() //=> "All"

isSameType(All, All(3)) //=> true
isSameType(All, All) //=> true
isSameType(All, Maybe.Just('3')) //=> false
isSameType(All(false), Maybe) //=> false
```

## Instance Methods

### concat
```haskell
All ~> All -> All
```

`concat` is used to combine (2) `Semigroup`s of the same type under an operation specified by the `Semigroup`. In the case of `All`, it will combine the two using logical AND (conjunction).

```js
All(true).concat(All(true)) //=> All false
Copy link
Owner Author

Choose a reason for hiding this comment

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

This should result to All true

All(true).concat(All(false)) //=> All false
All(false).concat(All(true)) //=> All false
All(false).concat(All(false)) //=> All false
```

### value
Copy link
Owner Author

Choose a reason for hiding this comment

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

might as well name these to valueOf
due to: this PR

```haskell
All ~> () -> Boolean
```

`value` is used on all `crocks` `Monoid`s as a means of extraction. While the extraction is available, types that implement `value` are not necessarily a `Comonad`. This function is used primarily for convenience for some of the helper functions that ship with `crocks`. Calling `value` on an `All` instance will result in the underlying `Boolean` value.

```js
All(0).value() //=> false
All('string').value() //=> true

//=> false
All(true)
.concat('')
.value()
```
103 changes: 103 additions & 0 deletions src/Any/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Any
```haskell
Any Boolean
```
`Any` is a `Monoid` that will combine two values of any type using logical disjunction (OR) on their coerced `Boolean` values, mapping truth-y values to `true` and false-y values to `false`.

```js
const Any = require('crocks/Any')
const isNumber = require('crocks/predicates/isNumber')
const mconcatMap = require('crocks/helpers/mconcat')

const trueString = Any('string')
const falseString = Any('')
const object = Any({ nice: true })

trueString.concat(falseString)
//=> Any false

trueString.concat(object)
//=> Any true

const anyNumber =
mconcatMap(Any, isNumber)

anyNumber([ 'string', 3 ])
//=> Any true

anyNumber([ true, 'string' ])
//=> Any false
```

## Implements
`Semigroup`, `Monoid`

## Constructor Methods

### empty
```haskell
Any.empty :: () -> Any
```

`empty` provides the identity for the `Monoid` in that when the value it provides is `concat`ed to any other value, it will return the other value. In the case of `Any` the result of `empty` is `false`. `empty` is available on both the Constructor and the Instance for convenience.
```js
Any.empty() //=> Any true
Copy link
Owner Author

Choose a reason for hiding this comment

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

should be Any false


Any(true).concat(Any.empty()) //=> Any true
Any(false).concat(Any.empty()) //=> Any false
```


### type
```haskell
Any.type :: () -> String
```

`type` provides a string representation of the type name for a given type in `crocks`. While it is used mostly internally for law validation, it can be useful to the end user for debugging and building out custom types based on the standard `crocks` types. While type comparisons can easily be done manually by calling `type` on a given type, using the `isSameType` function hides much of the boilerplate. `type` is available on both the Constructor and the Instance for convenience.

```js
const Assign = require('crocks/Assign')
const isSameType = require('crocks/predicates/isSameType')

Any.type() //=> "Any"

isSameType(Any, Any(3)) //=> true
isSameType(Any, Any) //=> true
isSameType(Any(false), Assign) //=> false

//=> false
Copy link
Owner Author

Choose a reason for hiding this comment

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

move under

isSameType(Any, Assign({ food: 'always' }))
```

## Instance Methods

### concat
```haskell
Any ~> Any -> Any
```

`concat` is used to combine (2) `Semigroup`s of the same type under an operation specified by the `Semigroup`. In the case of `Any`, it will combine the two using logical OR (disjunction).

```js
Any(true).concat(Any(true)) //=> Any true
Any(true).concat(Any(false)) //=> Any true
Any(false).concat(Any(true)) //=> Any true
Any(false).concat(Any(false)) //=> Any false
```

### value
Copy link
Owner Author

Choose a reason for hiding this comment

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

might as well name these to valueOf
due to: this PR

```haskell
Any ~> () -> Boolean
```

`value` is used on all `crocks` `Monoid`s as a means of extraction. While the extraction is available, types that implement `value` are not necessarily a `Comonad`. This function is used primarily for convenience for some of the helper functions that ship with `crocks`. Calling `value` on an `Any` instance will result in the underlying `Boolean` value.

```js
Any(0).value() //=> false
Any('string').value() //=> true

//=> true
Any(45)
.concat('')
.value()
```
10 changes: 0 additions & 10 deletions src/Arrow/Arrow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ test('Arrow type', t => {
t.end()
})

test('Arrow value', t => {
const f = constant('dat function')
const a = Arrow(f)

t.ok(isFunction(a.value), 'is a function')
t.equal(a.value()(), f(), 'provides the wrapped function')

t.end()
})

test('Arrow runWith', t => {
const f = sinon.spy(identity)
const a = Arrow(f)
Expand Down
Loading