• Jump To … +
    booleans.js index.js lists.js numerals.js pairs.js predicates.js
  • booleans.js

  • ¶

    Check out my combinators-js library if you are interested in combinatory logic. A combinator is just a higher order function that uses only function application and earlier defined combinators to define a result from its arguments. Most of the functions declared here can be defined very simply in terms of combinators.

  • ¶

    True takes 2 arguments and returns the first. This is the K combinator

    True('first')('second') // => 'first'`
    
    export const True = a => _ => a
  • ¶

    False takes 2 arguments and returns the second. This is the KI combinator

    False('first')('second') // => 'second'
    
    export const False = _ => a => a
  • ¶

    If takes a predicate and two values, returning the first value if the predicate is True and the second if the predicate is False. This is the I** combinator

    If(True)('then')('else') // => 'then'
    If(False)('then')('else') // => 'else'
    
    export const If = a => b => c => a(b)(c)
  • ¶

    Standard ‘and’

    and(True)(True) // => True
    and(True)(False) // => False
    
    export const and = a => b => a(b)(a)
  • ¶

    Standard ‘or’

    or(True)(False) // => True
    or(False)(False) // => False
    
    export const or = a => b => a(a)(b)
  • ¶

    Standard ‘not’. This is the C combinator

    not(False) // => True
    not(True) // => False
    
    export const not = a => b => c => a(c)(b)
  • ¶

    Standard ‘xor’

    xor(True)(False) // => True
    xor(True)(True) // => False
    
    export const xor = a => b => c => d => a(b(d)(c))(b(c)(d))