conductor
Why I'm building conductorGitHub
v1.5.0
v1.5.0
  • Introduction
  • Overview
    • Introduction
    • Core concepts
  • API reference
    • always
    • append
    • apply
    • arity
    • branch
    • capitalize
    • compose
    • concat
    • curry
    • curryN
    • delay
    • dump
    • entries
    • equals
    • equalsBy
    • factory
    • filter
    • findIndex
    • flatten
    • flip
    • forEach
    • get
    • head
    • ifElse
    • identity
    • into
    • isPromise
    • iterate
    • join
    • keys
    • map
    • merge
    • mergeBy
    • next
    • not
    • pluck
    • prepend
    • random
    • reduce
    • replace
    • slice
    • some
    • split
    • take
    • then
    • toLowerCase
    • transduce
    • transformers
      • transformers/filter
      • transformers/map
    • type
    • upsert
    • values
  • Guides
    • example use cases
    • checkGuards
Powered by GitBook
On this page
  • description
  • examples
  • basic example
  • usage in a function composition
  1. API reference

not

PreviousnextNextpluck

Last updated 7 years ago

not :: Any input => Boolean negation

description

Returns the logical negation of the input value. It's the functional equivalent of the JavaScript not operator !. It can be very useful in a function composition chain, to avoid writing code like this:

compose(b => !b, some(...))

As you can see from the type signature, it obviously accepts Booleans as input values, but also values of any types. Just beware of .

examples

basic example

import { not } from 'conductor'

not(true) // false

usage in a function composition

import { compose, not } from 'conductor'

const illegal_characters = /[?:;!/-]/
const searchIllegalCharacters = str => illegal_characters.test(str)
const isValid = compose(not, searchIllegalCharacters)

Suppose we want have a function which checks if an input string is valid. The input is considered valid if does not contain any illegal characters. The illegal characters are listed in a regular expression. Then, we use to see if any of these characters is matched in the input string. Since our input is considered valid only if it searchIllegalCharacters returns false, we use the logical not operator to negate its result.

how JavaScript coerces values to their Boolean equivalents
RegExp.prototype.test