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 READMEs for All, Any and Arrow types #148

Merged
merged 3 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
118 changes: 118 additions & 0 deletions src/All/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# 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 true
All(true).concat(All(false)) //=> All false
All(false).concat(All(true)) //=> All false
All(false).concat(All(false)) //=> All false
```

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

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

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

//=> false
All(true)
.concat('')
.valueOf()
```
121 changes: 121 additions & 0 deletions src/Any/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# 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 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

isSameType(Any, Assign({ food: 'always' }))
//=> false
```

## 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
```

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

`valueOf` is used on all `crocks` `Monoid`s as a means of extraction. While the
extraction is available, types that implement `valueOf` 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).valueOf() //=> false
Any('string').valueOf() //=> true

//=> true
Any(45)
.concat('')
.valueOf()
```
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