ramda#includes TypeScript Examples

The following examples show how to use ramda#includes. 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: freeVars.ts    From interpreters with MIT License 6 votes vote down vote up
occursFree = (v: string, e: Program | Exp): boolean =>
    isBoolExp(e) ? false :
    isNumExp(e) ? false :
    isStrExp(e) ? false :
    isLitExp(e) ? false :
    isVarRef(e) ? (v === e.var) :
    isIfExp(e) ? occursFree(v, e.test) || occursFree(v, e.then) || occursFree(v, e.alt) :
    isProcExp(e) ? ! includes(v, map((p) => p.var, e.args)) &&
                   some((b) => occursFree(v, b), e.body) :
    isPrimOp(e) ? false :
    isAppExp(e) ? occursFree(v, e.rator) ||
                  some((rand) => occursFree(v, rand), e.rands) :
    isDefineExp(e) ? (v !== e.var.var) && occursFree(v, e.val) :
    isLetExp(e) ? false : // TODO
    isProgram(e) ? false : // TODO
    e
Example #2
Source File: substitute.ts    From interpreters with MIT License 6 votes vote down vote up
substitute = (body: CExp[], vars: string[], exps: CExp[]): CExp[] => {
    const subVarRef = (e: VarRef): CExp => {
        const pos = indexOf(e.var, vars);
        return ((pos > -1) ? exps[pos] : e);
    };
    
    const subProcExp = (e: ProcExp): ProcExp => {
        const argNames = map((x) => x.var, e.args);
        const subst = zip(vars, exps);
        const freeSubst = filter((ve) => !includes(first(ve), argNames), subst);
        return makeProcExp(
            e.args,
            substitute(
                e.body,
                map((x: KeyValuePair<string, CExp>) => x[0], freeSubst),
                map((x: KeyValuePair<string, CExp>) => x[1], freeSubst)
            )
        );
    };
    
    const sub = (e: CExp): CExp => isNumExp(e) ? e :
        isBoolExp(e) ? e :
        isPrimOp(e) ? e :
        isLitExp(e) ? e :
        isStrExp(e) ? e :
        isVarRef(e) ? subVarRef(e) :
        isIfExp(e) ? makeIfExp(sub(e.test), sub(e.then), sub(e.alt)) :
        isProcExp(e) ? subProcExp(e) :
        isAppExp(e) ? makeAppExp(sub(e.rator), map(sub, e.rands)) :
        e;
    
    return map(sub, body);
}
Example #3
Source File: L5-substitution-adt.ts    From interpreters with MIT License 5 votes vote down vote up
extendSub = (sub: Sub, v: TVar, te: TExp): Result<Sub> =>
    bind(makeSub([v], [te]), (sub2: Sub) => {
        const updatedTEs = map((te) => applySub(sub2, te), sub.tes);
        return includes(v.var, map(prop('var'), sub.vars)) ? makeSub(sub.vars, updatedTEs) :
               makeSub(cons(v, sub.vars), cons(te, updatedTEs));
    })
Example #4
Source File: graphql.ts    From react-js-tutorial with MIT License 5 votes vote down vote up
getCourses = ({ topic }: QueryParams) => {
  console.warn(topic);
  if (topic) {
    return coursesData.filter((course) => includes(topic, course.topic));
  } else {
    return coursesData;
  }
}