Skip to content

Commit

Permalink
add 3 recursors
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Feb 19, 2019
1 parent 02303a1 commit c832cba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions functions/recursors/count-dependencies.js
@@ -0,0 +1,13 @@
import createRecursor from "../create-recursor"
import fastclone from "fast-clone"

export let initial = {}

export let createReducer = () =>
function reducer (current, name) {
let counts = fastclone(current)
counts[name] = (counts[name] || 0) + 1
return counts
}

export default () => createRecursor(createReducer(), initial)
13 changes: 13 additions & 0 deletions functions/recursors/find-dependents.js
@@ -0,0 +1,13 @@
import createRecursor from "../create-recursor"

export let initial = []

export let createReducer = target =>
function reducer (current, name, info) {
let hasRequires = info.requires != null && typeof info.requires == "object"
return hasRequires && Object.keys(info.requires).includes(target)
? current.concat(name)
: current
}

export default target => createRecursor(createReducer(target), initial)
12 changes: 12 additions & 0 deletions functions/recursors/get-longest-name.js
@@ -0,0 +1,12 @@
import createRecursor from "../create-recursor"

export let initial = ""

export let createReducer = () =>
function reducer (longest, name) {
return name.length > longest.length
? name
: longest
}

export default () => createRecursor(createReducer(), initial)

0 comments on commit c832cba

Please sign in to comment.