本文整理汇总了TypeScript中ramda.flatten函数的典型用法代码示例。如果您正苦于以下问题:TypeScript flatten函数的具体用法?TypeScript flatten怎么用?TypeScript flatten使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flatten函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: deps
function deps(scss: string, exists: string[]): string[] {
let excludes = new Set(exists);
let lines = fs.readFileSync(scss, "utf-8").split("\n");
let imports = Optional.cat(lines.map(l => depFromLine(l).map(p => path.resolve(path.dirname(scss), `${p}.scss`))));
let targets = imports.filter(i => ! excludes.has(i));
return targets.concat(_.flatten(targets.map(t => deps(t, exists.concat(targets)))));
}
示例2: deps
function deps(file: string, exists: string[]): string[] {
let _deps = requires(fs.readFileSync(file, "utf-8"))
.map(dep => path.resolve(path.dirname(file), `${dep}.js`))
.filter(fs.existsSync)
.filter(dep => exists.indexOf(dep) == -1);
return _.uniq(_deps.concat(_.flatten(_deps.map(d => deps(d, exists.concat(_deps))))));
}
示例3: rowGenerator
export function rowGenerator(state: State, table: string, schema: RelationTree): Route[] {
let history: History = R.clone(state.history || []);
if (history.length >= state.options.relationLimit) {
return [];
}
let last = R.last(history);
let relation = schema[table].relations[last && last['table']];
let identifier = `${schema[table].model}_id`;
if (relation) {
history.push({
type: 'row',
table: table,
model: schema[table].model
});
}
else {
history[0] = {
type: 'row',
table: table,
model: schema[table].model,
identifier: identifier
};
}
let identifierString = state.options.idFormat === 'colons' ?
`:${identifier}` : `{${identifier}}`;
let newPath = relation ?
`${state.path}/${schema[table].model}` : `${state.path}/${identifierString}`;
let newState = {
options: state.options,
path: newPath,
history: history
};
let tables = R.flatten(Object.keys(schema[table].relations).map((relation) => {
if (schema[table].relations[relation] === 'one') {
return rowGenerator(newState, relation, schema);
}
else {
return tableGenerator(newState, relation, schema);
}
}));
return R.concat(
scopes.row.methods.map((method) => {
return {
path: newPath,
method: method,
history: history
};
}),
tables
);
};
示例4: subscribe
/**
* Subscribes to some paths in state. Allows the user to track a subset of
* data within the state that will be sent to them every time it changes.
*
* @param command The command received from the reactotron app.
*/
function subscribe(command: any) {
const trackedNode = trackedNodes[command.mstNodeName || "default"]
const paths: string[] = (command && command.payload && command.payload.paths) || []
if (trackedNode && trackedNode.node && paths) {
subscriptions = uniq(flatten(paths))
const state = getSnapshot(trackedNode.node)
sendSubscriptions(state)
}
}
示例5: getXAttrs
.map(function getXAttrs(outlines:Array<OutlineFolderParent>):Array<OutlineFeed> {
return flatten<any>( // fixme: use proper types!
map(
outline => isFeedItem(outline) ?
prop('$', outline) :
getXAttrs(getOutline(outline)),
outlines
)
);
})
示例6:
const getVocabularyRecursive = (node: AbstractNode): string[] => {
if (node instanceof Leaf) {
return node.getNewVocabulary();
}
const internalNode = node as InternalNode;
return R.uniq([
...internalNode.getNewVocabulary(),
...R.flatten<string>(
R.map(getVocabularyRecursive, internalNode.getChildren())
)
]);
};
示例7: getVocabulary
public getVocabulary(id: string): string[] {
if (this.getId() === id) {
return this.getNewVocabulary();
}
const nodesUntilId = takeWhile(
found => !found,
map(child => child.findEntity(id), this.getChildren())
);
const previousChildren = take(nodesUntilId.length + 1, this.getChildren());
return concat(
flatten<string>(map(node => node.getVocabulary(id), previousChildren)),
this.getNewVocabulary()
);
}
示例8: getLetters
public getLetters(id: string): string[] {
const newLetterArr: string[] = this.getNewLetter()
? ([this.getNewLetter()] as string[])
: [];
if (this.getId() === id) {
return newLetterArr;
}
const nodesUntilId = takeWhile(
found => !found,
map(child => child.findEntity(id), this.getChildren())
);
const previousChildren = take(nodesUntilId.length + 1, this.getChildren());
return concat(
flatten<string>(map(node => node.getLetters(id), previousChildren)),
newLetterArr
);
}
示例9: filter
},
// filter :: Filterable f => (a → Boolean) → f a → f a
filter(fn, list) {
return R.filter(fn, list)
},
// findIndex :: (a → Boolean) → [a] → Number
findIndex(field, val, list) {
return R.findIndex(R.propEq(field, val))(list)
},
// concat :: [a] → [a] → [a]
concat(listA, listB) {
return R.concat(listA, listB)
},
//flatten :: [a] → [b]
flatten(list) {
return R.flatten(list)
},
//// [{}] ////
// getFullObjByField :: k -> [a] -> [a] -> {k:v}
getFullObjByField(findField, partArr, fullArr) {
return R.filter(R.where({ [findField]: R.contains(R.__, partArr) }))(fullArr) // tslint:disable-line
},
// getAnotherField :: k -> [a] -> [a] -> {k:v} -> v
getAnotherField(anotherField, findField, partArr, fullArr) {
return this.pluck(anotherField, this.getFullObjByField(findField, partArr, fullArr))
},
// getArrObjByFieldValue :: (k->v->[{k:v}]) -> {k:v}
getArrObjByFieldValue(field, filedValue, list) {
return this.filter(R.propEq(field, filedValue), list)[0]
},
示例10: getPolygonFromPoints
y
})
},
getPolygonFromPoints (points: TwoDimensionalPoint[]): Line {
const pointsSorted = R.sortWith([
R.ascend(R.prop('x')),
R.ascend(R.prop('y'))
])(points) as TwoDimensionalPoint[]
const minPoint = pointsSorted[0]
const maxPoint = R.last(pointsSorted)
const pointsBellow = [minPoint].concat(pointsSorted.filter(point => {
return isPointBellow(point, minPoint) && isPointBellow(point, maxPoint) && !R.equals(point, maxPoint)
}))
const pointsBellowPath = flatten ( zip( R.pluck('x', pointsBellow), R.pluck('y', pointsBellow) ) ) as number[]
const pointsAbove = R.sortWith([
R.descend(R.prop('x')),
R.descend(R.prop('y'))
]
)(R.difference(pointsSorted, pointsBellow))
const pointsAbovePath = flatten ( zip( R.pluck('x', pointsAbove), R.pluck('y', pointsAbove) ) ) as number[]
return new Line({
points: pointsBellowPath.concat(pointsAbovePath),
closed: true,
stroke: '#fff',
strokeWidth: 2,
tension: 0.2
})