ramda#chain TypeScript Examples
The following examples show how to use
ramda#chain.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TExp.ts From interpreters with MIT License | 6 votes |
unparseTExp = (te: TExp): Result<string> => {
const unparseTuple = (paramTes: TExp[]): Result<string[]> =>
isEmpty(paramTes) ? makeOk(["Empty"]) :
bind(unparseTExp(first(paramTes)), (paramTE: string) =>
mapv(mapResult(unparseTExp, rest(paramTes)), (paramTEs: string[]) =>
cons(paramTE, chain(te => ['*', te], paramTEs))));
const up = (x?: TExp): Result<string | string[]> =>
isNumTExp(x) ? makeOk('number') :
isBoolTExp(x) ? makeOk('boolean') :
isStrTExp(x) ? makeOk('string') :
isVoidTExp(x) ? makeOk('void') :
isEmptyTVar(x) ? makeOk(x.var) :
isTVar(x) ? up(tvarContents(x)) :
isProcTExp(x) ? bind(unparseTuple(x.paramTEs), (paramTEs: string[]) =>
mapv(unparseTExp(x.returnTE), (returnTE: string) =>
[...paramTEs, '->', returnTE])) :
isEmptyTupleTExp(x) ? makeOk("Empty") :
isNonEmptyTupleTExp(x) ? unparseTuple(x.TEs) :
x === undefined ? makeFailure("Undefined TVar") :
x;
const unparsed = up(te);
return mapv(unparsed,
(x: string | string[]) => isString(x) ? x :
isArray(x) ? `(${x.join(' ')})` :
x);
}
Example #2
Source File: lzt.ts From interpreters with MIT License | 6 votes |
// Breadth-first traversal of a lzt as a generator
export function* lztBFS$<Node>(lzt: LazyTree<Node>): Generator<Node> {
function* traverseTrees$(trees: Array<LazyTree<Node>>): Generator<Node> {
if (isEmpty(trees))
return [];
for (const t of trees) {
if (isLZT(t)) yield t.root;
}
yield* traverseTrees$(chain(lztChildren, trees));
}
if (isEmptyLZT(lzt))
return [];
yield* traverseTrees$([lzt]);
}
Example #3
Source File: annotations.ts From checkstyle-github-action with MIT License | 6 votes |
export function annotationsForPath(resultFile: string): Annotation[] {
core.info(`Creating annotations for ${resultFile}`)
const root: string = process.env['GITHUB_WORKSPACE'] || ''
const result: CheckstyleReport = parser.parse(
fs.readFileSync(resultFile, 'UTF-8' as BufferEncoding),
XML_PARSE_OPTIONS
)
return chain(file => {
return map(violation => {
const annotation: Annotation = {
annotation_level: getWarningLevel(violation.severity),
path: path.relative(root, file.name),
start_line: Number(violation.line || 1),
end_line: Number(violation.line || 1),
title: violation.source,
message: decode(violation.message)
}
return annotation
}, asArray(file.error))
}, asArray<File>(result.checkstyle?.file))
}
Example #4
Source File: lzt.ts From interpreters with MIT License | 5 votes |
lztDfs = <Node>(lzt: LazyTree<Node>): Array<Node> =>
isEmptyLZT(lzt) ? [] :
cons(lzt.root, chain(lztDfs, lztChildren(lzt)))
Example #5
Source File: lzt.ts From interpreters with MIT License | 5 votes |
lztFilter = <Node>(pred: (n: Node)=>boolean, lzt: LazyTree<Node>): Array<Node> =>
isEmptyLZT(lzt) ? [] :
pred(lzt.root) ? cons(lzt.root, chain((child: LazyTree<Node>) => lztFilter(pred, child), lztChildren(lzt))) :
chain((child : LazyTree<Node>) => lztFilter(pred, child), lztChildren(lzt))
Example #6
Source File: main.ts From checkstyle-github-action with MIT License | 5 votes |
async function run(): Promise<void> {
try {
const path = core.getInput(Inputs.Path, {required: true})
const name = core.getInput(Inputs.Name)
const title = core.getInput(Inputs.Title)
const searchResult = await findResults(path)
if (searchResult.filesToUpload.length === 0) {
core.warning(
`No files were found for the provided path: ${path}. No results will be uploaded.`
)
} else {
core.info(
`With the provided path, there will be ${searchResult.filesToUpload.length} results uploaded`
)
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
const annotations: Annotation[] = chain(
annotationsForPath,
searchResult.filesToUpload
)
core.debug(
`Grouping ${annotations.length} annotations into chunks of ${MAX_ANNOTATIONS_PER_REQUEST}`
)
const groupedAnnotations: Annotation[][] =
annotations.length > MAX_ANNOTATIONS_PER_REQUEST
? splitEvery(MAX_ANNOTATIONS_PER_REQUEST, annotations)
: [annotations]
core.debug(`Created ${groupedAnnotations.length} buckets`)
const conclusion = getConclusion(annotations)
for (const annotationSet of groupedAnnotations) {
await createCheck(
name,
title,
annotationSet,
annotations.length,
conclusion
)
}
}
} catch (error) {
core.setFailed(error instanceof Error ? error : String(error))
}
}
Example #7
Source File: annotations.ts From spotbugs-github-action with MIT License | 5 votes |
export function annotationsForPath(resultFile: string): Annotation[] {
core.info(`Creating annotations for ${resultFile}`)
const root: string = process.env['GITHUB_WORKSPACE'] || ''
const result: FindbugsResult = parser.parse(
fs.readFileSync(resultFile, 'UTF-8' as BufferEncoding),
XML_PARSE_OPTIONS
)
const violations = asArray(result?.BugCollection?.BugInstance)
const bugPatterns: {[type: string]: BugPattern} = indexBy(
a => a.type,
asArray(result?.BugCollection?.BugPattern)
)
core.info(`${resultFile} has ${violations.length} violations`)
const getFilePath: (sourcePath: string) => string | undefined = memoizeWith(
identity,
(sourcePath: string) =>
asArray(result?.BugCollection?.Project?.SrcDir).find(SrcDir => {
const combinedPath = path.join(SrcDir, sourcePath)
const fileExists = fs.existsSync(combinedPath)
core.debug(`${combinedPath} ${fileExists ? 'does' : 'does not'} exists`)
return fileExists
})
)
return chain(BugInstance => {
const annotationsForBug: Annotation[] = []
const sourceLines = asArray(BugInstance.SourceLine)
const primarySourceLine: SourceLine | undefined =
sourceLines.length > 1
? sourceLines.find(sl => sl.primary)
: sourceLines[0]
const SrcDir: string | undefined =
primarySourceLine?.sourcepath &&
getFilePath(primarySourceLine?.sourcepath)
if (primarySourceLine?.start && SrcDir) {
const annotation: Annotation = {
annotation_level: AnnotationLevel.warning,
path: path.relative(
root,
path.join(SrcDir, primarySourceLine?.sourcepath)
),
start_line: Number(primarySourceLine?.start || 1),
end_line: Number(
primarySourceLine?.end || primarySourceLine?.start || 1
),
title: BugInstance.type,
message: BugInstance.LongMessage,
raw_details: htmlToText(
decode(bugPatterns[BugInstance.type].Details),
HTML_TO_TEXT_OPTIONS
)
}
annotationsForBug.push(annotation)
} else {
core.debug(
`Skipping bug instance because source line start or source directory are missing`
)
}
return annotationsForBug
}, violations)
}
Example #8
Source File: main.ts From spotbugs-github-action with MIT License | 5 votes |
async function run(): Promise<void> {
try {
const path = core.getInput(Inputs.Path, {required: true})
const name = core.getInput(Inputs.Name)
const title = core.getInput(Inputs.Title)
const searchResult = await findResults(path)
if (searchResult.filesToUpload.length === 0) {
core.warning(
`No files were found for the provided path: ${path}. No results will be uploaded.`
)
} else {
core.info(
`With the provided path, there will be ${searchResult.filesToUpload.length} results uploaded`
)
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
const annotations: Annotation[] = chain(
annotationsForPath,
searchResult.filesToUpload
)
core.debug(
`Grouping ${annotations.length} annotations into chunks of ${MAX_ANNOTATIONS_PER_REQUEST}`
)
const groupedAnnotations: Annotation[][] =
annotations.length > MAX_ANNOTATIONS_PER_REQUEST
? splitEvery(MAX_ANNOTATIONS_PER_REQUEST, annotations)
: [annotations]
core.debug(`Created ${groupedAnnotations.length} buckets`)
for (const annotationSet of groupedAnnotations) {
await createCheck(name, title, annotationSet, annotations.length)
}
}
} catch (error) {
core.setFailed(error instanceof Error ? error : String(error))
}
}