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

feat(docs): add predicate, point-free, and transformation functions in index page #532

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodejs 10.24.1
python 2.7.18 3.10.5
40 changes: 40 additions & 0 deletions bin/docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/bash

set -e

function main()
{
local section="$1"

case $section in
predicates)
generate_predicates;;
*)
echo "usage: ./bin/docs.sh <section>";;
esac
}

function generate_predicates()
{
local section=$1

local cmd='file="${0}" && \
grep "$(basename ${file%.*}) ::" "$file" | \
sed -E "s/\s*\/\*\* (.*) :: (.*) \*\//| [\`\1\`][\1] | \`\2\` | \`crocks\/predicates\/\1\` |/"'

local predicates=$(find "./src/predicates/" \
-name "*.js" \
-not -name "*.spec.js}" \
-exec bash -c "$cmd" {} \;)

local core=$(find "./src/core/" \
-name "*.js" \
-not -name "*.spec.js}" \
-exec bash -c "$cmd" {} \;)

local manualAppend='| [`propPathEq`][propPathEq] | `[ String | Number ] -> a -> Object -> Boolean` | `crocks/predicates/propPathEq` |\n| [`propPathSatisfies`][propPathSatisfies] | `[ (String | Integer) ] -> (a -> Boolean) -> b -> Boolean` | `crocks/predicates/propPathSatisfies` |'

echo -e "${predicates}\n${core}\n${manualAppend}" | sort
}

main "$@"
106 changes: 106 additions & 0 deletions docs/src/pages/docs/functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,61 @@ type: `Pred a` and vice-versa
| [`unless`][unless] | `(a -> Boolean) -> (a -> a) -> a -> a` | `crocks/logic/unless` |
| [`when`][when] | `(a -> Boolean) -> (a -> a) -> a -> a` | `crocks/logic/when` |

## Predicate

| Function | Signature | Location |
|:---|:---|:---|
| [`hasProp`][hasProp] | `(String or Integer) -> a -> Boolean` | `crocks/predicates/hasProp` |
| [`hasPropPath`][hasPropPath] | `[ String or Integer ] -> a -> Boolean` | `crocks/predicates/hasPropPath` |
| [`hasProps`][hasProps] | `Foldable f => f (String or Integer) -> a -> Boolean` | `crocks/predicates/hasProps` |
| [`isAlternative`][isAlternative] | `a -> Boolean` | `crocks/predicates/isAlternative` |
| [`isAlt`][isAlt] | `a -> Boolean` | `crocks/predicates/isAlt` |
| [`isApplicative`][isApplicative] | `a -> Boolean` | `crocks/predicates/isApplicative` |
| [`isApply`][isApply] | `a -> Boolean` | `crocks/predicates/isApply` |
| [`isArray`][isArray] | `a -> Boolean` | `crocks/predicates/isArray` |
| [`isBichain`][isBichain] | `a -> Boolean` | `crocks/predicates/isBichain` |
| [`isBifunctor`][isBifunctor] | `a -> Boolean` | `crocks/predicates/isBifunctor` |
| [`isBoolean`][isBoolean] | `a -> Boolean` | `crocks/predicates/isBoolean` |
| [`isCategory`][isCategory] | `a -> Boolean` | `crocks/predicates/isCategory` |
| [`isChain`][isChain] | `a -> Boolean` | `crocks/predicates/isChain` |
| [`isContravariant`][isContravariant] | `a -> Boolean` | `crocks/predicates/isContravariant` |
| [`isDate`][isDate] | `a -> Boolean` | `crocks/predicates/isDate` |
| [`isDefined`][isDefined] | `a -> Boolean` | `crocks/predicates/isDefined` |
| [`isEmpty`][isEmpty] | `a -> Boolean` | `crocks/predicates/isEmpty` |
| [`isExtend`][isExtend] | `a -> Boolean` | `crocks/predicates/isExtend` |
| [`isFalse`][isFalse] | `a -> Boolean` | `crocks/predicates/isFalse` |
| [`isFalsy`][isFalsy] | `a -> Boolean` | `crocks/predicates/isFalsy` |
| [`isFoldable`][isFoldable] | `a -> Boolean` | `crocks/predicates/isFoldable` |
| [`isFunction`][isFunction] | `a -> Boolean` | `crocks/predicates/isFunction` |
| [`isFunctor`][isFunctor] | `a -> Boolean` | `crocks/predicates/isFunctor` |
| [`isInteger`][isInteger] | `a -> Boolean` | `crocks/predicates/isInteger` |
| [`isIterable`][isIterable] | `a -> Boolean` | `crocks/predicates/isIterable` |
| [`isMap`][isMap] | `a -> Boolean` | `crocks/predicates/isMap` |
| [`isMonad`][isMonad] | `a -> Boolean` | `crocks/predicates/isMonad` |
| [`isMonoid`][isMonoid] | `a -> Boolean` | `crocks/predicates/isMonoid` |
| [`isNil`][isNil] | `a -> Boolean` | `crocks/predicates/isNil` |
| [`isNumber`][isNumber] | `a -> Boolean` | `crocks/predicates/isNumber` |
| [`isObject`][isObject] | `a -> Boolean` | `crocks/predicates/isObject` |
| [`isPlus`][isPlus] | `a -> Boolean` | `crocks/predicates/isPlus` |
| [`isProfunctor`][isProfunctor] | `a -> Boolean` | `crocks/predicates/isProfunctor` |
| [`isPromise`][isPromise] | `a -> Boolean` | `crocks/predicates/isPromise` |
| [`isSame`][isSame] | `(a, b) -> Boolean` | `crocks/predicates/isSame` |
| [`isSameType`][isSameType] | `Container m => (m, m) -> Boolean` | `crocks/predicates/isSameType` |
| [`isSemigroup`][isSemigroup] | `a -> Boolean` | `crocks/predicates/isSemigroup` |
| [`isSemigroupoid`][isSemigroupoid] | `a -> Boolean` | `crocks/predicates/isSemigroupoid` |
| [`isSetoid`][isSetoid] | `a -> Boolean` | `crocks/predicates/isSetoid` |
| [`isString`][isString] | `a -> Boolean` | `crocks/predicates/isString` |
| [`isSymbol`][isSymbol] | `a -> Boolean` | `crocks/predicates/isSymbol` |
| [`isTraversable`][isTraversable] | `a -> Boolean` | `crocks/predicates/isTraversable` |
| [`isTrue`][isTrue] | `a -> Boolean` | `crocks/predicates/isTrue` |
| [`isTruthy`][isTruthy] | `a -> Boolean` | `crocks/predicates/isTruthy` |
| [`pathEq`][pathEq] | `[ String or Number ] -> a -> Object -> Boolean` | `crocks/predicates/pathEq` |
| [`pathSatisfies`][pathSatisfies] | `[ (String or Integer) ] -> (a -> Boolean) -> b -> Boolean` | `crocks/predicates/pathSatisfies` |
| [`propEq`][propEq] | `(String or Integer) -> a -> b -> Boolean` | `crocks/predicates/propEq` |
| [`propPathEq`][propPathEq] | `[ String or Number ] -> a -> Object -> Boolean` | `crocks/predicates/propPathEq` |
| [`propPathSatisfies`][propPathSatisfies] | `[ (String or Integer) ] -> (a -> Boolean) -> b -> Boolean` | `crocks/predicates/propPathSatisfies` |
| [`propSatisfies`][propSatisfies] | `(String or Integer) -> (a -> Boolean) -> b -> Boolean` | `crocks/predicates/propSatisfies` |

[monoids]: ../monoids/index.html
[crocks]: ../crocks/index.html
[pred]: ../crocks/Pred.html
Expand Down Expand Up @@ -199,3 +254,54 @@ type: `Pred a` and vice-versa
[or]: logic-functions.html#or
[unless]: logic-functions.html#unless
[when]: logic-functions.html#when

[hasProp]: predicate-functions.html
[hasPropPath]: predicate-functions.html
[hasProps]: predicate-functions.html
[isAlternative]: predicate-functions.html
[isAlt]: predicate-functions.html
[isApplicative]: predicate-functions.html
[isApply]: predicate-functions.html
[isArray]: predicate-functions.html
[isBichain]: predicate-functions.html
[isBifunctor]: predicate-functions.html
[isBoolean]: predicate-functions.html
[isCategory]: predicate-functions.html
[isChain]: predicate-functions.html
[isContravariant]: predicate-functions.html
[isDate]: predicate-functions.html
[isDefined]: predicate-functions.html
[isEmpty]: predicate-functions.html
[isExtend]: predicate-functions.html
[isFalse]: predicate-functions.html
[isFalsy]: predicate-functions.html
[isFoldable]: predicate-functions.html
[isFunction]: predicate-functions.html
[isFunctor]: predicate-functions.html
[isInteger]: predicate-functions.html
[isIterable]: predicate-functions.html
[isMap]: predicate-functions.html
[isMonad]: predicate-functions.html
[isMonoid]: predicate-functions.html
[isNil]: predicate-functions.html
[isNumber]: predicate-functions.html
[isObject]: predicate-functions.html
[isPlus]: predicate-functions.html
[isProfunctor]: predicate-functions.html
[isPromise]: predicate-functions.html
[isSame]: predicate-functions.html
[isSameType]: predicate-functions.html
[isSemigroup]: predicate-functions.html
[isSemigroupoid]: predicate-functions.html
[isSetoid]: predicate-functions.html
[isString]: predicate-functions.html
[isSymbol]: predicate-functions.html
[isTraversable]: predicate-functions.html
[isTrue]: predicate-functions.html
[isTruthy]: predicate-functions.html
[pathEq]: predicate-functions.html
[pathSatisfies]: predicate-functions.html
[propEq]: predicate-functions.html
[propPathEq]: predicate-functions.html
[propPathSatisfies]: predicate-functions.html
[propSatisfies]: predicate-functions.html
1 change: 1 addition & 0 deletions src/core/isArray.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @license ISC License (c) copyright 2016 original and current authors */
/** @author Ian Hofmann-Hicks (evil) */

/** isArray :: a -> Boolean */
function isArray(x) {
return Array.isArray(x)
}
Expand Down
1 change: 1 addition & 0 deletions src/core/isDefined.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @license ISC License (c) copyright 2017 original and current authors */
/** @author Ian Hofmann-Hicks (evil) */

/** isDefined :: a -> Boolean */
function isDefined(x) {
return x !== undefined
}
Expand Down
1 change: 1 addition & 0 deletions src/core/isEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const isMonoid = require('./isMonoid')
const equals = require('./equals')
const fl = require('./flNames')

/** isEmpty :: a -> Boolean */
function isEmpty(x) {
if(isMonoid(x)) {
const empty = x.constructor[fl['empty']] || x.constructor['empty'] || x['empty']
Expand Down
1 change: 1 addition & 0 deletions src/core/isIterable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const isFunction = require('./isFunction')
const isNil = require('./isNil')

/** isIterable :: a -> Boolean */
function isIterable(iterable) {
return !isNil(iterable) && isFunction(iterable[Symbol.iterator])
}
Expand Down
1 change: 1 addition & 0 deletions src/core/isMap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @license ISC License (c) copyright 2019 original and current authors */
/** @author Benny Powers (bennypowers) */

/** isMap :: a -> Boolean */
function isMap(x) {
return x instanceof Map
}
Expand Down
4 changes: 2 additions & 2 deletions src/predicates/pathSatisfies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const err = name =>
`${name}: First argument must be an Array of non-empty Strings or Integers`

function fn(name) {
// pathSatisfies: [ (String | Integer) ] -> (a -> Boolean) -> b -> Boolean
// pathSatisfies: [ (String | Integer) ] -> Pred a -> b -> Boolean
/** pathSatisfies :: [ (String | Integer) ] -> (a -> Boolean) -> b -> Boolean */
/** pathSatisfies :: [ (String | Integer) ] -> Pred a -> b -> Boolean */
function pathSatisfies(keys, pred, x) {
if(!isArray(keys)) {
throw new TypeError(err(name))
Expand Down
2 changes: 1 addition & 1 deletion src/predicates/propEq.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const isInteger = require('../core/isInteger')
const isNil = require('../core/isNil')
const isString = require('../core/isString')

// propEq: (String | Integer) -> a -> b -> Boolean
/** propEq :: (String | Integer) -> a -> b -> Boolean */
function propEq(key, value, x) {
if(!(isString(key) && !isEmpty(key) || isInteger(key))) {
throw new TypeError(
Expand Down
4 changes: 2 additions & 2 deletions src/predicates/propSatisfies.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const isPredOrFunc = require('../core/isPredOrFunc')
const isString = require('../core/isString')
const predOrFunc = require('../core/predOrFunc')

// propSatisfies: (String | Integer) -> (a -> Boolean) -> b -> Boolean
// propSatisfies: (String | Integer) -> Pred a -> b -> Boolean
/** propSatisfies :: (String | Integer) -> (a -> Boolean) -> b -> Boolean */
/** propSatisfies :: (String | Integer) -> Pred a -> b -> Boolean */
function propSatisfies(key, pred, x) {
if(!(isString(key) && !isEmpty(key) || isInteger(key))) {
throw new TypeError(
Expand Down