ramda#identity TypeScript Examples
The following examples show how to use
ramda#identity.
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: server-utils.ts From anthem with Apache License 2.0 | 6 votes |
updateAmounts = ifElse(
({ value }: ITxMsg) => {
const { amount } = value as IMsgDelegate;
return Boolean(amount && Array.isArray(amount));
},
updateFn,
identity,
)
Example #2
Source File: useNextQuestion.tsx From nosgestesclimat-site with MIT License | 6 votes |
export function getNextSteps(
missingVariables: Array<MissingVariables>
): Array<DottedName> {
const byCount = ([, [count]]: [unknown, [number]]) => count
const byScore = ([, [, score]]: [unknown, [unknown, number]]) => score
const missingByTotalScore = reduce<MissingVariables, MissingVariables>(
mergeWith(add),
{},
missingVariables
)
const innerKeys = flatten(map(keys, missingVariables)),
missingByTargetsAdvanced = Object.fromEntries(
Object.entries(countBy(identity, innerKeys)).map(
// Give higher score to top level questions
([name, score]) => [
name,
score + Math.max(0, 4 - name.split('.').length),
]
)
)
const missingByCompound = mergeWith(
pair,
missingByTargetsAdvanced,
missingByTotalScore
),
pairs = toPairs<number>(missingByCompound),
sortedPairs = sortWith([descend(byCount), descend(byScore) as any], pairs)
return map(head, sortedPairs) as any
}
Example #3
Source File: graphql.ts From react-js-tutorial with MIT License | 6 votes |
coursesData = times<Course>(
(idx): Course => ({
id: identity(idx),
title: faker.company.companyName(),
author: `${faker.name.firstName()} ${faker.name.lastName()}`,
description: faker.lorem.words(),
topic: faker.lorem.paragraph(),
url: faker.internet.url(),
}),
30
)
Example #4
Source File: L6-eval.ts From interpreters with MIT License | 5 votes |
topCont: Cont = identity
Example #5
Source File: L7c-eval.ts From interpreters with MIT License | 5 votes |
up = (exp: Exp | undefined): string =>
exp ? either(unparse(exp), identity, identity) : "undefined"
Example #6
Source File: L7c-eval.ts From interpreters with MIT License | 5 votes |
pv = (v: Result<Value> | undefined): string =>
v ? either(v, valueToString, identity) : "undefined"
Example #7
Source File: L7c-eval.ts From interpreters with MIT License | 5 votes |
pvs = (vs: Result<Value[]> | undefined): string =>
vs ? either(vs, values => `[${join(", ", map(pv, map(makeOk, values)))}]`, identity) : "undefined"
Example #8
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 #9
Source File: processDatabase.ts From kanel with MIT License | 4 votes |
processDatabase = async ({
connection,
preDeleteModelFolder = false,
customTypeMap = {},
modelHooks = [],
modelNominator = nameIdentity,
propertyNominator = (propertyName) =>
propertyName.indexOf(' ') !== -1 ? `'${propertyName}'` : propertyName,
initializerNominator = (modelName) => `${modelName}Initializer`,
idNominator = (modelName) => `${modelName}Id`,
makeIdType = (innerType, modelName) =>
`${innerType} & { " __flavor"?: '${modelName}' };`,
typeHooks = [],
typeNominator = nameIdentity,
fileNominator = identity,
resolveViews = false,
schemas,
...unknownProps
}: Config) => {
if (!isEmpty(unknownProps)) {
logger.warn(
`Unknown configuration properties: ${Object.keys(unknownProps).join(
', '
)}`
);
}
const typeMap = { ...defaultTypeMap, ...customTypeMap };
/** @type {import('./Config').Nominators} */
const nominators = {
modelNominator,
propertyNominator,
initializerNominator,
idNominator,
typeNominator,
fileNominator,
};
const modelProcessChain = [...defaultHooks, ...modelHooks];
const typeProcessChain = [...defaultHooks, ...typeHooks];
if (typeof connection === 'string') {
logger.log(`Connecting to ${chalk.greenBright(connection)}`);
} else {
logger.log(
`Connecting to ${chalk.greenBright(connection.database)} on ${
connection.host
}`
);
}
const schemaFolderMap = map(
(s: SchemaConfig) => path.resolve(s.modelFolder),
indexBy((s) => s.name, schemas)
) as Record<string, string>;
for (const schemaConfig of schemas) {
const schema = await extractSchema(
schemaConfig.name,
connection,
schemaConfig.resolveViews !== undefined
? schemaConfig.resolveViews
: resolveViews
);
if (preDeleteModelFolder) {
logger.log(` - Clearing old files in ${schemaConfig.modelFolder}`);
await rmfr(schemaConfig.modelFolder, { glob: true });
}
if (!fs.existsSync(schemaConfig.modelFolder)) {
fs.mkdirSync(schemaConfig.modelFolder, { recursive: true });
}
await processSchema(
schemaConfig,
schema,
typeMap,
nominators,
modelProcessChain,
typeProcessChain,
schemaFolderMap,
makeIdType
);
}
}