diff --git a/README.md b/README.md index c09900bc..047edf0f 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ const $ = window.sanctuaryDef; ### Configure -#### `create :: { checkTypes :: Boolean, env :: Array Type } -⁠> Module` +#### `create :: { checkTypes :: Boolean, env :: Array Type } -⁠> Module` Takes an options record and returns a Sanctuary module. `checkTypes` specifies whether to enable type checking. The module's polymorphic @@ -396,7 +396,7 @@ S.map (S.sub (1)) (Identity (43)); See also [`env`](#env). -#### `env :: Array Type` +#### `env :: Array Type` The Sanctuary module's environment (`(S.create ({checkTypes, env})).env` is a reference to `env`). Useful in conjunction with [`create`](#create). @@ -436,7 +436,7 @@ is a reference to `env`). Useful in conjunction with [`create`](#create). . $.ValidNumber ] ``` -#### `unchecked :: Module` +#### `unchecked :: Module` A complete Sanctuary module which performs no type checking. This is useful as it permits operations which Sanctuary's type checking would @@ -458,7 +458,7 @@ Opting out of type checking may cause type errors to go unnoticed. ### Classify -#### `type :: Any -⁠> { namespace :: Maybe String, name :: String, version :: NonNegativeInteger }` +#### `type :: Any -⁠> { namespace :: Maybe String, name :: String, version :: NonNegativeInteger }` Returns the result of parsing the [type identifier][] of the given value. @@ -470,7 +470,7 @@ Returns the result of parsing the [type identifier][] of the given value. {namespace: Nothing, name: 'Array', version: 0} ``` -#### `is :: Type -⁠> Any -⁠> Boolean` +#### `is :: Type -⁠> Any -⁠> Boolean` Returns `true` [iff][] the given value is a member of the specified type. See [`$.test`][] for details. @@ -485,7 +485,7 @@ false ### Showable -#### `show :: Any -⁠> String` +#### `show :: Any -⁠> String` Alias of [`show`][]. @@ -507,7 +507,7 @@ Alias of [`show`][]. Sanctuary is compatible with the [Fantasy Land][] specification. -#### `equals :: Setoid a => a -⁠> a -⁠> Boolean` +#### `equals :: Setoid a => a -⁠> a -⁠> Boolean` Curried version of [`Z.equals`][] which requires two arguments of the same type. @@ -530,7 +530,7 @@ true false ``` -#### `lt :: Ord a => a -⁠> a -⁠> Boolean` +#### `lt :: Ord a => a -⁠> a -⁠> Boolean` Returns `true` [iff][] the *second* argument is less than the first according to [`Z.lt`][]. @@ -540,7 +540,7 @@ according to [`Z.lt`][]. [1, 2] ``` -#### `lte :: Ord a => a -⁠> a -⁠> Boolean` +#### `lte :: Ord a => a -⁠> a -⁠> Boolean` Returns `true` [iff][] the *second* argument is less than or equal to the first according to [`Z.lte`][]. @@ -550,7 +550,7 @@ the first according to [`Z.lte`][]. [1, 2, 3] ``` -#### `gt :: Ord a => a -⁠> a -⁠> Boolean` +#### `gt :: Ord a => a -⁠> a -⁠> Boolean` Returns `true` [iff][] the *second* argument is greater than the first according to [`Z.gt`][]. @@ -560,7 +560,7 @@ according to [`Z.gt`][]. [4, 5] ``` -#### `gte :: Ord a => a -⁠> a -⁠> Boolean` +#### `gte :: Ord a => a -⁠> a -⁠> Boolean` Returns `true` [iff][] the *second* argument is greater than or equal to the first according to [`Z.gte`][]. @@ -570,7 +570,7 @@ to the first according to [`Z.gte`][]. [3, 4, 5] ``` -#### `min :: Ord a => a -⁠> a -⁠> a` +#### `min :: Ord a => a -⁠> a -⁠> a` Returns the smaller of its two arguments (according to [`Z.lte`][]). @@ -587,7 +587,7 @@ new Date ('1999-12-31') '10' ``` -#### `max :: Ord a => a -⁠> a -⁠> a` +#### `max :: Ord a => a -⁠> a -⁠> a` Returns the larger of its two arguments (according to [`Z.lte`][]). @@ -604,7 +604,7 @@ new Date ('2000-01-01') '2' ``` -#### `clamp :: Ord a => a -⁠> a -⁠> a -⁠> a` +#### `clamp :: Ord a => a -⁠> a -⁠> a -⁠> a` Takes a lower bound, an upper bound, and a value of the same type. Returns the value if it is within the bounds; the nearer bound otherwise. @@ -622,7 +622,7 @@ See also [`min`](#min) and [`max`](#max). 'Z' ``` -#### `id :: Category c => TypeRep c -⁠> c` +#### `id :: Category c => TypeRep c -⁠> c` [Type-safe][sanctuary-def] version of [`Z.id`][]. @@ -631,7 +631,7 @@ See also [`min`](#min) and [`max`](#max). 42 ``` -#### `concat :: Semigroup a => a -⁠> a -⁠> a` +#### `concat :: Semigroup a => a -⁠> a -⁠> a` Curried version of [`Z.concat`][]. @@ -652,7 +652,7 @@ Just ([1, 2, 3, 4, 5, 6]) Sum (42) ``` -#### `empty :: Monoid a => TypeRep a -⁠> a` +#### `empty :: Monoid a => TypeRep a -⁠> a` [Type-safe][sanctuary-def] version of [`Z.empty`][]. @@ -670,7 +670,7 @@ Sum (42) Sum (0) ``` -#### `invert :: Group g => g -⁠> g` +#### `invert :: Group g => g -⁠> g` [Type-safe][sanctuary-def] version of [`Z.invert`][]. @@ -679,7 +679,7 @@ Sum (0) Sum (-5) ``` -#### `filter :: Filterable f => (a -⁠> Boolean) -⁠> f a -⁠> f a` +#### `filter :: Filterable f => (a -⁠> Boolean) -⁠> f a -⁠> f a` Curried version of [`Z.filter`][]. Discards every element which does not satisfy the predicate. @@ -703,7 +703,7 @@ Nothing Just (1) ``` -#### `reject :: Filterable f => (a -⁠> Boolean) -⁠> f a -⁠> f a` +#### `reject :: Filterable f => (a -⁠> Boolean) -⁠> f a -⁠> f a` Curried version of [`Z.reject`][]. Discards every element which satisfies the predicate. @@ -727,7 +727,7 @@ Just (0) Nothing ``` -#### `takeWhile :: Filterable f => (a -⁠> Boolean) -⁠> f a -⁠> f a` +#### `takeWhile :: Filterable f => (a -⁠> Boolean) -⁠> f a -⁠> f a` Curried version of [`Z.takeWhile`][]. Discards the first element which does not satisfy the predicate, and all subsequent elements. @@ -742,7 +742,7 @@ See also [`dropWhile`](#dropWhile). [] ``` -#### `dropWhile :: Filterable f => (a -⁠> Boolean) -⁠> f a -⁠> f a` +#### `dropWhile :: Filterable f => (a -⁠> Boolean) -⁠> f a -⁠> f a` Curried version of [`Z.dropWhile`][]. Retains the first element which does not satisfy the predicate, and all subsequent elements. @@ -757,7 +757,7 @@ See also [`takeWhile`](#takeWhile). [3, 3, 3, 7, 6, 3, 5, 4] ``` -#### `map :: Functor f => (a -⁠> b) -⁠> f a -⁠> f b` +#### `map :: Functor f => (a -⁠> b) -⁠> f a -⁠> f b` Curried version of [`Z.map`][]. @@ -793,7 +793,7 @@ from combinatory logic (i.e. [`compose`](#compose)): 10 ``` -#### `flip :: Functor f => f (a -⁠> b) -⁠> a -⁠> f b` +#### `flip :: Functor f => f (a -⁠> b) -⁠> a -⁠> f b` Curried version of [`Z.flip`][]. Maps over the given functions, applying each to the given value. @@ -822,7 +822,7 @@ from combinatory logic: Cons (1) (Cons (2) (Nil)) ``` -#### `bimap :: Bifunctor f => (a -⁠> b) -⁠> (c -⁠> d) -⁠> f a c -⁠> f b d` +#### `bimap :: Bifunctor f => (a -⁠> b) -⁠> (c -⁠> d) -⁠> f a c -⁠> f b d` Curried version of [`Z.bimap`][]. @@ -837,7 +837,7 @@ Left ('FOO') Right (8) ``` -#### `mapLeft :: Bifunctor f => (a -⁠> b) -⁠> f a c -⁠> f b c` +#### `mapLeft :: Bifunctor f => (a -⁠> b) -⁠> f a c -⁠> f b c` Curried version of [`Z.mapLeft`][]. Maps the given function over the left side of a Bifunctor. @@ -853,7 +853,7 @@ Left ('FOO') Right (64) ``` -#### `promap :: Profunctor p => (a -⁠> b) -⁠> (c -⁠> d) -⁠> p b c -⁠> p a d` +#### `promap :: Profunctor p => (a -⁠> b) -⁠> (c -⁠> d) -⁠> p b c -⁠> p a d` Curried version of [`Z.promap`][]. @@ -862,7 +862,7 @@ Curried version of [`Z.promap`][]. 11 ``` -#### `alt :: Alt f => f a -⁠> f a -⁠> f a` +#### `alt :: Alt f => f a -⁠> f a -⁠> f a` Curried version of [`Z.alt`][]. @@ -880,7 +880,7 @@ Right (1) Right (2) ``` -#### `zero :: Plus f => TypeRep f -⁠> f a` +#### `zero :: Plus f => TypeRep f -⁠> f a` [Type-safe][sanctuary-def] version of [`Z.zero`][]. @@ -895,7 +895,7 @@ Right (2) Nothing ``` -#### `reduce :: Foldable f => (b -⁠> a -⁠> b) -⁠> b -⁠> f a -⁠> b` +#### `reduce :: Foldable f => (b -⁠> a -⁠> b) -⁠> b -⁠> f a -⁠> b` Takes a curried binary function, an initial value, and a [Foldable][], and applies the function to the initial value and the Foldable's first @@ -913,7 +913,7 @@ otherwise. [5, 4, 3, 2, 1] ``` -#### `traverse :: (Applicative f, Traversable t) => TypeRep f -⁠> (a -⁠> f b) -⁠> t a -⁠> f (t b)` +#### `traverse :: (Applicative f, Traversable t) => TypeRep f -⁠> (a -⁠> f b) -⁠> t a -⁠> f (t b)` Curried version of [`Z.traverse`][]. @@ -937,7 +937,7 @@ Just ({a: 10, b: 11, c: 12}) Nothing ``` -#### `sequence :: (Applicative f, Traversable t) => TypeRep f -⁠> t (f a) -⁠> f (t a)` +#### `sequence :: (Applicative f, Traversable t) => TypeRep f -⁠> t (f a) -⁠> f (t a)` Curried version of [`Z.sequence`][]. Inverts the given `t (f a)` to produce an `f (t a)`. @@ -959,7 +959,7 @@ Just ({a: 1, b: 2, c: 3}) Nothing ``` -#### `ap :: Apply f => f (a -⁠> b) -⁠> f a -⁠> f b` +#### `ap :: Apply f => f (a -⁠> b) -⁠> f a -⁠> f b` Curried version of [`Z.ap`][]. @@ -989,7 +989,7 @@ from combinatory logic: 'Hask' ``` -#### `lift2 :: Apply f => (a -⁠> b -⁠> c) -⁠> f a -⁠> f b -⁠> f c` +#### `lift2 :: Apply f => (a -⁠> b -⁠> c) -⁠> f a -⁠> f b -⁠> f c` Promotes a curried binary function to a function which operates on two [Apply][]s. @@ -1008,7 +1008,7 @@ Just (true) Just (false) ``` -#### `lift3 :: Apply f => (a -⁠> b -⁠> c -⁠> d) -⁠> f a -⁠> f b -⁠> f c -⁠> f d` +#### `lift3 :: Apply f => (a -⁠> b -⁠> c -⁠> d) -⁠> f a -⁠> f b -⁠> f c -⁠> f d` Promotes a curried ternary function to a function which operates on three [Apply][]s. @@ -1021,7 +1021,7 @@ Just (6) Nothing ``` -#### `apFirst :: Apply f => f a -⁠> f b -⁠> f a` +#### `apFirst :: Apply f => f a -⁠> f b -⁠> f a` Curried version of [`Z.apFirst`][]. Combines two effectful actions, keeping only the result of the first. Equivalent to Haskell's `(<*)` @@ -1037,7 +1037,7 @@ See also [`apSecond`](#apSecond). Just (1) ``` -#### `apSecond :: Apply f => f a -⁠> f b -⁠> f b` +#### `apSecond :: Apply f => f a -⁠> f b -⁠> f b` Curried version of [`Z.apSecond`][]. Combines two effectful actions, keeping only the result of the second. Equivalent to Haskell's `(*>)` @@ -1053,7 +1053,7 @@ See also [`apFirst`](#apFirst). Just (2) ``` -#### `of :: Applicative f => TypeRep f -⁠> a -⁠> f a` +#### `of :: Applicative f => TypeRep f -⁠> a -⁠> f a` Curried version of [`Z.of`][]. @@ -1071,7 +1071,7 @@ Just (42) Right (42) ``` -#### `chain :: Chain m => (a -⁠> m b) -⁠> m a -⁠> m b` +#### `chain :: Chain m => (a -⁠> m b) -⁠> m a -⁠> m b` Curried version of [`Z.chain`][]. @@ -1089,7 +1089,7 @@ Just (123) Nothing ``` -#### `join :: Chain m => m (m a) -⁠> m a` +#### `join :: Chain m => m (m a) -⁠> m a` [Type-safe][sanctuary-def] version of [`Z.join`][]. Removes one level of nesting from a nested monadic structure. @@ -1120,7 +1120,7 @@ from combinatory logic: 'abcabc' ``` -#### `chainRec :: ChainRec m => TypeRep m -⁠> (a -⁠> m (Either a b)) -⁠> a -⁠> m b` +#### `chainRec :: ChainRec m => TypeRep m -⁠> (a -⁠> m (Either a b)) -⁠> a -⁠> m b` Performs a [`chain`](#chain)-like computation with constant stack usage. Similar to [`Z.chainRec`][], but curried and more convenient due to the @@ -1134,7 +1134,7 @@ use of the Either type to indicate completion (via a Right). ['oo!', 'oo?', 'on!', 'on?', 'no!', 'no?', 'nn!', 'nn?'] ``` -#### `extend :: Extend w => (w a -⁠> b) -⁠> w a -⁠> w b` +#### `extend :: Extend w => (w a -⁠> b) -⁠> w a -⁠> w b` Curried version of [`Z.extend`][]. @@ -1146,7 +1146,7 @@ Curried version of [`Z.extend`][]. [4, 3, 2, 1] ``` -#### `duplicate :: Extend w => w a -⁠> w (w a)` +#### `duplicate :: Extend w => w a -⁠> w (w a)` [Type-safe][sanctuary-def] version of [`Z.duplicate`][]. Adds one level of nesting to a comonadic structure. @@ -1165,7 +1165,7 @@ Just (Just (1)) [4, 3, 2, 1] ``` -#### `extract :: Comonad w => w a -⁠> a` +#### `extract :: Comonad w => w a -⁠> a` [Type-safe][sanctuary-def] version of [`Z.extract`][]. @@ -1174,7 +1174,7 @@ Just (Just (1)) 'bar' ``` -#### `contramap :: Contravariant f => (b -⁠> a) -⁠> f a -⁠> f b` +#### `contramap :: Contravariant f => (b -⁠> a) -⁠> f a -⁠> f b` [Type-safe][sanctuary-def] version of [`Z.contramap`][]. @@ -1185,7 +1185,7 @@ Just (Just (1)) ### Combinator -#### `I :: a -⁠> a` +#### `I :: a -⁠> a` The I combinator. Returns its argument. Equivalent to Haskell's `id` function. @@ -1195,7 +1195,7 @@ function. 'foo' ``` -#### `K :: a -⁠> b -⁠> a` +#### `K :: a -⁠> b -⁠> a` The K combinator. Takes two values and returns the first. Equivalent to Haskell's `const` function. @@ -1208,7 +1208,7 @@ Haskell's `const` function. [42, 42, 42, 42, 42] ``` -#### `T :: a -⁠> (a -⁠> b) -⁠> b` +#### `T :: a -⁠> (a -⁠> b) -⁠> b` The T ([thrush][]) combinator. Takes a value and a function, and returns the result of applying the function to the value. Equivalent to Haskell's @@ -1224,7 +1224,7 @@ the result of applying the function to the value. Equivalent to Haskell's ### Function -#### `curry2 :: ((a, b) -⁠> c) -⁠> a -⁠> b -⁠> c` +#### `curry2 :: ((a, b) -⁠> c) -⁠> a -⁠> b -⁠> c` Curries the given binary function. @@ -1233,7 +1233,7 @@ Curries the given binary function. [10, 100, 1000] ``` -#### `curry3 :: ((a, b, c) -⁠> d) -⁠> a -⁠> b -⁠> c -⁠> d` +#### `curry3 :: ((a, b, c) -⁠> d) -⁠> a -⁠> b -⁠> c -⁠> d` Curries the given ternary function. @@ -1246,7 +1246,7 @@ Curries the given ternary function. 'orange icecream' ``` -#### `curry4 :: ((a, b, c, d) -⁠> e) -⁠> a -⁠> b -⁠> c -⁠> d -⁠> e` +#### `curry4 :: ((a, b, c, d) -⁠> e) -⁠> a -⁠> b -⁠> c -⁠> d -⁠> e` Curries the given quaternary function. @@ -1259,7 +1259,7 @@ Curries the given quaternary function. {x: 0, y: 0, width: 10, height: 10} ``` -#### `curry5 :: ((a, b, c, d, e) -⁠> f) -⁠> a -⁠> b -⁠> c -⁠> d -⁠> e -⁠> f` +#### `curry5 :: ((a, b, c, d, e) -⁠> f) -⁠> a -⁠> b -⁠> c -⁠> d -⁠> e -⁠> f` Curries the given quinary function. @@ -1278,7 +1278,7 @@ Curries the given quinary function. ### Composition -#### `compose :: Semigroupoid s => s b c -⁠> s a b -⁠> s a c` +#### `compose :: Semigroupoid s => s b c -⁠> s a b -⁠> s a c` Curried version of [`Z.compose`][]. @@ -1295,7 +1295,7 @@ See also [`pipe`](#pipe). 10 ``` -#### `pipe :: Foldable f => f (Any -⁠> Any) -⁠> a -⁠> b` +#### `pipe :: Foldable f => f (Any -⁠> Any) -⁠> a -⁠> b` Takes a sequence of functions assumed to be unary and a value of any type, and returns the result of applying the sequence of transformations @@ -1309,7 +1309,7 @@ of functions. `pipe ([f, g, h]) (x)` is equivalent to `h (g (f (x)))`. 9 ``` -#### `pipeK :: (Foldable f, Chain m) => f (Any -⁠> m Any) -⁠> m a -⁠> m b` +#### `pipeK :: (Foldable f, Chain m) => f (Any -⁠> m Any) -⁠> m a -⁠> m b` Takes a sequence of functions assumed to be unary which return values with a [Chain][], and a value of that Chain, and returns the result @@ -1324,7 +1324,7 @@ of an sequence of functions. `pipeK ([f, g, h]) (x)` is equivalent to Just (3) ``` -#### `on :: (b -⁠> b -⁠> c) -⁠> (a -⁠> b) -⁠> a -⁠> a -⁠> c` +#### `on :: (b -⁠> b -⁠> c) -⁠> (a -⁠> b) -⁠> a -⁠> a -⁠> c` Takes a binary function `f`, a unary function `g`, and two values `x` and `y`. Returns `f (g (x)) (g (y))`. @@ -1343,11 +1343,11 @@ contains exactly two values: one of type `a`; one of type `b`. The implementation is provided by [sanctuary-pair][]. -#### `PairType :: Type -⁠> Type -⁠> Type` +#### `PairType :: Type -⁠> Type -⁠> Type` A [`BinaryType`][BinaryType] for use with [sanctuary-def][]. -#### `Pair :: a -⁠> b -⁠> Pair a b` +#### `Pair :: a -⁠> b -⁠> Pair a b` Pair's sole data constructor. Additionally, it serves as the Pair [type representative][]. @@ -1357,7 +1357,16 @@ Pair [type representative][]. Pair ('foo') (42) ``` -#### `fst :: Pair a b -⁠> a` +#### `pair :: (a -⁠> b -⁠> c) -⁠> Pair a b -⁠> c` + +Case analysis for the `Pair a b` type. + +```javascript +> S.pair (S.concat) (S.Pair ('foo') ('bar')) +'foobar' +``` + +#### `fst :: Pair a b -⁠> a` `fst (Pair (x) (y))` is equivalent to `x`. @@ -1366,7 +1375,7 @@ Pair ('foo') (42) 'foo' ``` -#### `snd :: Pair a b -⁠> b` +#### `snd :: Pair a b -⁠> b` `snd (Pair (x) (y))` is equivalent to `y`. @@ -1375,7 +1384,7 @@ Pair ('foo') (42) 42 ``` -#### `swap :: Pair a b -⁠> Pair b a` +#### `swap :: Pair a b -⁠> Pair b a` `swap (Pair (x) (y))` is equivalent to `Pair (y) (x)`. @@ -1391,15 +1400,15 @@ either Nothing (the empty value) or a Just whose value is of type `a`. The implementation is provided by [sanctuary-maybe][]. -#### `MaybeType :: Type -⁠> Type` +#### `MaybeType :: Type -⁠> Type` A [`UnaryType`][UnaryType] for use with [sanctuary-def][]. -#### `Maybe :: TypeRep Maybe` +#### `Maybe :: TypeRep Maybe` Maybe [type representative][]. -#### `Nothing :: Maybe a` +#### `Nothing :: Maybe a` The empty value of type `Maybe a`. @@ -1408,7 +1417,7 @@ The empty value of type `Maybe a`. Nothing ``` -#### `Just :: a -⁠> Maybe a` +#### `Just :: a -⁠> Maybe a` Constructs a value of type `Maybe a` from a value of type `a`. @@ -1417,7 +1426,7 @@ Constructs a value of type `Maybe a` from a value of type `a`. Just (42) ``` -#### `isNothing :: Maybe a -⁠> Boolean` +#### `isNothing :: Maybe a -⁠> Boolean` Returns `true` if the given Maybe is Nothing; `false` if it is a Just. @@ -1429,7 +1438,7 @@ true false ``` -#### `isJust :: Maybe a -⁠> Boolean` +#### `isJust :: Maybe a -⁠> Boolean` Returns `true` if the given Maybe is a Just; `false` if it is Nothing. @@ -1441,7 +1450,7 @@ true false ``` -#### `fromMaybe :: a -⁠> Maybe a -⁠> a` +#### `fromMaybe :: a -⁠> Maybe a -⁠> a` Takes a default value and a Maybe, and returns the Maybe's value if the Maybe is a Just; the default value otherwise. @@ -1457,7 +1466,7 @@ See also [`fromMaybe_`](#fromMaybe_) and 0 ``` -#### `fromMaybe_ :: (() -⁠> a) -⁠> Maybe a -⁠> a` +#### `fromMaybe_ :: (() -⁠> a) -⁠> Maybe a -⁠> a` Variant of [`fromMaybe`](#fromMaybe) which takes a thunk so the default value is only computed if required. @@ -1472,7 +1481,7 @@ value is only computed if required. 832040 ``` -#### `maybeToNullable :: Maybe a -⁠> Nullable a` +#### `maybeToNullable :: Maybe a -⁠> Nullable a` Returns the given Maybe's value if the Maybe is a Just; `null` otherwise. [Nullable][] is defined in [sanctuary-def][]. @@ -1487,7 +1496,7 @@ See also [`fromMaybe`](#fromMaybe). null ``` -#### `toMaybe :: a? -⁠> Maybe a` +#### `toMaybe :: a? -⁠> Maybe a` Takes a value and returns Nothing if the value is `null` or `undefined`; Just the value otherwise. @@ -1500,7 +1509,7 @@ Nothing Just (42) ``` -#### `maybe :: b -⁠> (a -⁠> b) -⁠> Maybe a -⁠> b` +#### `maybe :: b -⁠> (a -⁠> b) -⁠> Maybe a -⁠> b` Takes a value of any type, a function, and a Maybe. If the Maybe is a Just, the return value is the result of applying the function to @@ -1516,7 +1525,7 @@ See also [`maybe_`](#maybe_). 0 ``` -#### `maybe_ :: (() -⁠> b) -⁠> (a -⁠> b) -⁠> Maybe a -⁠> b` +#### `maybe_ :: (() -⁠> b) -⁠> (a -⁠> b) -⁠> Maybe a -⁠> b` Variant of [`maybe`](#maybe) which takes a thunk so the default value is only computed if required. @@ -1531,7 +1540,7 @@ is only computed if required. 832040 ``` -#### `justs :: (Filterable f, Functor f) => f (Maybe a) -⁠> f a` +#### `justs :: (Filterable f, Functor f) => f (Maybe a) -⁠> f a` Discards each element which is Nothing, and unwraps each element which is a Just. Related to Haskell's `catMaybes` function. @@ -1543,7 +1552,7 @@ See also [`lefts`](#lefts) and [`rights`](#rights). ['foo', 'baz'] ``` -#### `mapMaybe :: (Filterable f, Functor f) => (a -⁠> Maybe b) -⁠> f a -⁠> f b` +#### `mapMaybe :: (Filterable f, Functor f) => (a -⁠> Maybe b) -⁠> f a -⁠> f b` Takes a function and a structure, applies the function to each element of the structure, and returns the "successful" results. If the result of @@ -1558,7 +1567,7 @@ if the result is a Just, the Just's value is included. {x: 1, z: 4} ``` -#### `encase :: (a -⁠> b) -⁠> a -⁠> Maybe b` +#### `encase :: (a -⁠> b) -⁠> a -⁠> Maybe b` Takes a unary function `f` which may throw and a value `x` of any type, and applies `f` to `x` inside a `try` block. If an exception is caught, @@ -1575,15 +1584,15 @@ Just (2) Nothing ``` -#### `encase2 :: (a -⁠> b -⁠> c) -⁠> a -⁠> b -⁠> Maybe c` +#### `encase2 :: (a -⁠> b -⁠> c) -⁠> a -⁠> b -⁠> Maybe c` Binary version of [`encase`](#encase). -#### `encase3 :: (a -⁠> b -⁠> c -⁠> d) -⁠> a -⁠> b -⁠> c -⁠> Maybe d` +#### `encase3 :: (a -⁠> b -⁠> c -⁠> d) -⁠> a -⁠> b -⁠> c -⁠> Maybe d` Ternary version of [`encase`](#encase). -#### `maybeToEither :: a -⁠> Maybe b -⁠> Either a b` +#### `maybeToEither :: a -⁠> Maybe b -⁠> Either a b` Converts a Maybe to an Either. Nothing becomes a Left (containing the first argument); a Just becomes a Right. @@ -1606,15 +1615,15 @@ value is of type `b`. The implementation is provided by [sanctuary-either][]. -#### `EitherType :: Type -⁠> Type -⁠> Type` +#### `EitherType :: Type -⁠> Type -⁠> Type` A [`BinaryType`][BinaryType] for use with [sanctuary-def][]. -#### `Either :: TypeRep Either` +#### `Either :: TypeRep Either` Either [type representative][]. -#### `Left :: a -⁠> Either a b` +#### `Left :: a -⁠> Either a b` Constructs a value of type `Either a b` from a value of type `a`. @@ -1623,7 +1632,7 @@ Constructs a value of type `Either a b` from a value of type `a`. Left ('Cannot divide by zero') ``` -#### `Right :: b -⁠> Either a b` +#### `Right :: b -⁠> Either a b` Constructs a value of type `Either a b` from a value of type `b`. @@ -1632,7 +1641,7 @@ Constructs a value of type `Either a b` from a value of type `b`. Right (42) ``` -#### `isLeft :: Either a b -⁠> Boolean` +#### `isLeft :: Either a b -⁠> Boolean` Returns `true` if the given Either is a Left; `false` if it is a Right. @@ -1644,7 +1653,7 @@ true false ``` -#### `isRight :: Either a b -⁠> Boolean` +#### `isRight :: Either a b -⁠> Boolean` Returns `true` if the given Either is a Right; `false` if it is a Left. @@ -1656,7 +1665,7 @@ true false ``` -#### `fromEither :: b -⁠> Either a b -⁠> b` +#### `fromEither :: b -⁠> Either a b -⁠> b` Takes a default value and an Either, and returns the Right value if the Either is a Right; the default value otherwise. @@ -1669,7 +1678,7 @@ if the Either is a Right; the default value otherwise. 0 ``` -#### `toEither :: a -⁠> b? -⁠> Either a b` +#### `toEither :: a -⁠> b? -⁠> Either a b` Converts an arbitrary value to an Either: a Left if the value is `null` or `undefined`; a Right otherwise. The first argument specifies the @@ -1693,7 +1702,7 @@ Left ('Invalid protocol') Right ('https:') ``` -#### `either :: (a -⁠> c) -⁠> (b -⁠> c) -⁠> Either a b -⁠> c` +#### `either :: (a -⁠> c) -⁠> (b -⁠> c) -⁠> Either a b -⁠> c` Takes two functions and an Either, and returns the result of applying the first function to the Left's value, if the Either @@ -1708,7 +1717,7 @@ Right's value, if the Either is a Right. '42' ``` -#### `lefts :: (Filterable f, Functor f) => f (Either a b) -⁠> f a` +#### `lefts :: (Filterable f, Functor f) => f (Either a b) -⁠> f a` Discards each element which is a Right, and unwraps each element which is a Left. @@ -1720,7 +1729,7 @@ See also [`rights`](#rights). ['foo', 'bar'] ``` -#### `rights :: (Filterable f, Functor f) => f (Either a b) -⁠> f b` +#### `rights :: (Filterable f, Functor f) => f (Either a b) -⁠> f b` Discards each element which is a Left, and unwraps each element which is a Right. @@ -1732,7 +1741,7 @@ See also [`lefts`](#lefts). [20, 10] ``` -#### `tagBy :: (a -⁠> Boolean) -⁠> a -⁠> Either a a` +#### `tagBy :: (a -⁠> Boolean) -⁠> a -⁠> Either a a` Takes a predicate and a value, and returns a Right of the value if it satisfies the predicate; a Left of the value otherwise. @@ -1745,7 +1754,7 @@ Left (0) Right (1) ``` -#### `encaseEither :: (Error -⁠> l) -⁠> (a -⁠> r) -⁠> a -⁠> Either l r` +#### `encaseEither :: (Error -⁠> l) -⁠> (a -⁠> r) -⁠> a -⁠> Either l r` Takes two unary functions, `f` and `g`, the second of which may throw, and a value `x` of any type. Applies `g` to `x` inside a `try` block. @@ -1766,15 +1775,15 @@ Left (new SyntaxError ('Unexpected end of JSON input')) Left ('Unexpected end of JSON input') ``` -#### `encaseEither2 :: (Error -⁠> l) -⁠> (a -⁠> b -⁠> r) -⁠> a -⁠> b -⁠> Either l r` +#### `encaseEither2 :: (Error -⁠> l) -⁠> (a -⁠> b -⁠> r) -⁠> a -⁠> b -⁠> Either l r` Binary version of [`encaseEither`](#encaseEither). -#### `encaseEither3 :: (Error -⁠> l) -⁠> (a -⁠> b -⁠> c -⁠> r) -⁠> a -⁠> b -⁠> c -⁠> Either l r` +#### `encaseEither3 :: (Error -⁠> l) -⁠> (a -⁠> b -⁠> c -⁠> r) -⁠> a -⁠> b -⁠> c -⁠> Either l r` Ternary version of [`encaseEither`](#encaseEither). -#### `eitherToMaybe :: Either a b -⁠> Maybe b` +#### `eitherToMaybe :: Either a b -⁠> Maybe b` Converts an Either to a Maybe. A Left becomes Nothing; a Right becomes a Just. @@ -1791,7 +1800,7 @@ Just (42) ### Logic -#### `and :: Boolean -⁠> Boolean -⁠> Boolean` +#### `and :: Boolean -⁠> Boolean -⁠> Boolean` Boolean "and". @@ -1809,7 +1818,7 @@ false true ``` -#### `or :: Boolean -⁠> Boolean -⁠> Boolean` +#### `or :: Boolean -⁠> Boolean -⁠> Boolean` Boolean "or". @@ -1827,7 +1836,7 @@ true true ``` -#### `not :: Boolean -⁠> Boolean` +#### `not :: Boolean -⁠> Boolean` Boolean "not". @@ -1841,7 +1850,7 @@ true false ``` -#### `complement :: (a -⁠> Boolean) -⁠> a -⁠> Boolean` +#### `complement :: (a -⁠> Boolean) -⁠> a -⁠> Boolean` Takes a unary predicate and a value of any type, and returns the logical negation of applying the predicate to the value. @@ -1856,7 +1865,7 @@ true false ``` -#### `boolean :: a -⁠> a -⁠> Boolean -⁠> a` +#### `boolean :: a -⁠> a -⁠> Boolean -⁠> a` Case analysis for the `Boolean` type. `boolean (x) (y) (b)` evaluates to `x` if `b` is `false`; to `y` if `b` is `true`. @@ -1869,7 +1878,7 @@ to `x` if `b` is `false`; to `y` if `b` is `true`. 'yes' ``` -#### `ifElse :: (a -⁠> Boolean) -⁠> (a -⁠> b) -⁠> (a -⁠> b) -⁠> a -⁠> b` +#### `ifElse :: (a -⁠> Boolean) -⁠> (a -⁠> b) -⁠> (a -⁠> b) -⁠> a -⁠> b` Takes a unary predicate, a unary "if" function, a unary "else" function, and a value of any type, and returns the result of @@ -1887,7 +1896,7 @@ See also [`when`](#when) and [`unless`](#unless). 4 ``` -#### `when :: (a -⁠> Boolean) -⁠> (a -⁠> a) -⁠> a -⁠> a` +#### `when :: (a -⁠> Boolean) -⁠> (a -⁠> a) -⁠> a -⁠> a` Takes a unary predicate, a unary function, and a value of any type, and returns the result of applying the function to the value if the value @@ -1903,7 +1912,7 @@ See also [`unless`](#unless) and [`ifElse`](#ifElse). -1 ``` -#### `unless :: (a -⁠> Boolean) -⁠> (a -⁠> a) -⁠> a -⁠> a` +#### `unless :: (a -⁠> Boolean) -⁠> (a -⁠> a) -⁠> a -⁠> a` Takes a unary predicate, a unary function, and a value of any type, and returns the result of applying the function to the value if the value @@ -1919,7 +1928,7 @@ See also [`when`](#when) and [`ifElse`](#ifElse). -1 ``` -#### `allPass :: Foldable f => f (a -⁠> Boolean) -⁠> a -⁠> Boolean` +#### `allPass :: Foldable f => f (a -⁠> Boolean) -⁠> a -⁠> Boolean` Takes a structure containing zero or more predicates, and a value of any type. Returns `true` [iff][] the value satisfies all of the @@ -1934,7 +1943,7 @@ true false ``` -#### `anyPass :: Foldable f => f (a -⁠> Boolean) -⁠> a -⁠> Boolean` +#### `anyPass :: Foldable f => f (a -⁠> Boolean) -⁠> a -⁠> Boolean` Takes a structure containing zero or more predicates, and a value of any type. Returns `true` [iff][] the value satisfies any of the @@ -1951,7 +1960,7 @@ false ### Array -#### `array :: b -⁠> (a -⁠> Array a -⁠> b) -⁠> Array a -⁠> b` +#### `array :: b -⁠> (a -⁠> Array a -⁠> b) -⁠> Array a -⁠> b` Case analysis for the `Array a` type. @@ -1969,7 +1978,7 @@ Nothing Just ([2, 3]) ``` -#### `slice :: Integer -⁠> Integer -⁠> Array a -⁠> Maybe (Array a)` +#### `slice :: Integer -⁠> Integer -⁠> Array a -⁠> Maybe (Array a)` Takes a start index `i`, an end index `j`, and an array, and returns Just the `[i,j)` slice of the array if possible; Nothing otherwise. @@ -1989,7 +1998,7 @@ Just (['c', 'd']) Nothing ``` -#### `at :: Integer -⁠> Array a -⁠> Maybe a` +#### `at :: Integer -⁠> Array a -⁠> Maybe a` Returns Just the element of the given array at the specified index if the index is within the array's bounds; Nothing otherwise. A negative @@ -2006,10 +2015,10 @@ Nothing Just ('d') ``` -#### `head :: Array a -⁠> Maybe a` +#### `head :: Foldable f => f a -⁠> Maybe a` -Returns Just the first element of the given array if the array contains -at least one element; Nothing otherwise. +Returns Just the first element of the given structure if the structure +contains at least one element; Nothing otherwise. ```javascript > S.head ([1, 2, 3]) @@ -2017,12 +2026,18 @@ Just (1) > S.head ([]) Nothing + +> S.head (Cons (1) (Cons (2) (Cons (3) (Nil)))) +Just (1) + +> S.head (Nil) +Nothing ``` -#### `last :: Array a -⁠> Maybe a` +#### `last :: Foldable f => f a -⁠> Maybe a` -Returns Just the last element of the given array if the array contains -at least one element; Nothing otherwise. +Returns Just the last element of the given structure if the structure +contains at least one element; Nothing otherwise. ```javascript > S.last ([1, 2, 3]) @@ -2030,12 +2045,18 @@ Just (3) > S.last ([]) Nothing + +> S.last (Cons (1) (Cons (2) (Cons (3) (Nil)))) +Just (3) + +> S.last (Nil) +Nothing ``` -#### `tail :: Array a -⁠> Maybe (Array a)` +#### `tail :: (Applicative f, Foldable f, Monoid (f a)) => f a -⁠> Maybe (f a)` -Returns Just all but the first of the given array's elements if the -array contains at least one element; Nothing otherwise. +Returns Just all but the first of the given structure's elements if the +structure contains at least one element; Nothing otherwise. ```javascript > S.tail ([1, 2, 3]) @@ -2043,12 +2064,18 @@ Just ([2, 3]) > S.tail ([]) Nothing + +> S.tail (Cons (1) (Cons (2) (Cons (3) (Nil)))) +Just (Cons (2) (Cons (3) (Nil))) + +> S.tail (Nil) +Nothing ``` -#### `init :: Array a -⁠> Maybe (Array a)` +#### `init :: (Applicative f, Foldable f, Monoid (f a)) => f a -⁠> Maybe (f a)` -Returns Just all but the last of the given array's elements if the -array contains at least one element; Nothing otherwise. +Returns Just all but the last of the given structure's elements if the +structure contains at least one element; Nothing otherwise. ```javascript > S.init ([1, 2, 3]) @@ -2056,9 +2083,15 @@ Just ([1, 2]) > S.init ([]) Nothing + +> S.init (Cons (1) (Cons (2) (Cons (3) (Nil)))) +Just (Cons (1) (Cons (2) (Nil))) + +> S.init (Nil) +Nothing ``` -#### `take :: Integer -⁠> Array a -⁠> Maybe (Array a)` +#### `take :: Integer -⁠> Array a -⁠> Maybe (Array a)` Returns Just the first N elements of the given array if N is greater than or equal to zero and less than or equal to the length of the array; @@ -2075,7 +2108,7 @@ Just (['a', 'b', 'c', 'd', 'e']) Nothing ``` -#### `takeLast :: Integer -⁠> Array a -⁠> Maybe (Array a)` +#### `takeLast :: Integer -⁠> Array a -⁠> Maybe (Array a)` Returns Just the last N elements of the given array if N is greater than or equal to zero and less than or equal to the length of the array; @@ -2092,7 +2125,7 @@ Just (['a', 'b', 'c', 'd', 'e']) Nothing ``` -#### `drop :: Integer -⁠> Array a -⁠> Maybe (Array a)` +#### `drop :: Integer -⁠> Array a -⁠> Maybe (Array a)` Returns Just all but the first N elements of the given array if N is greater than or equal to zero and less than or equal to the length of @@ -2109,7 +2142,7 @@ Just ([]) Nothing ``` -#### `dropLast :: Integer -⁠> Array a -⁠> Maybe (Array a)` +#### `dropLast :: Integer -⁠> Array a -⁠> Maybe (Array a)` Returns Just all but the last N elements of the given array if N is greater than or equal to zero and less than or equal to the length of @@ -2126,7 +2159,7 @@ Just ([]) Nothing ``` -#### `size :: Foldable f => f a -⁠> Integer` +#### `size :: Foldable f => f a -⁠> Integer` Returns the number of elements of the given structure. @@ -2153,7 +2186,7 @@ Returns the number of elements of the given structure. 1 ``` -#### `all :: Foldable f => (a -⁠> Boolean) -⁠> f a -⁠> Boolean` +#### `all :: Foldable f => (a -⁠> Boolean) -⁠> f a -⁠> Boolean` Returns `true` [iff][] all the elements of the structure satisfy the predicate. @@ -2171,7 +2204,7 @@ true false ``` -#### `any :: Foldable f => (a -⁠> Boolean) -⁠> f a -⁠> Boolean` +#### `any :: Foldable f => (a -⁠> Boolean) -⁠> f a -⁠> Boolean` Returns `true` [iff][] any element of the structure satisfies the predicate. @@ -2189,7 +2222,7 @@ false true ``` -#### `none :: Foldable f => (a -⁠> Boolean) -⁠> f a -⁠> Boolean` +#### `none :: Foldable f => (a -⁠> Boolean) -⁠> f a -⁠> Boolean` Returns `true` [iff][] none of the elements of the structure satisfies the predicate. @@ -2215,7 +2248,7 @@ true false ``` -#### `append :: (Applicative f, Semigroup (f a)) => a -⁠> f a -⁠> f a` +#### `append :: (Applicative f, Semigroup (f a)) => a -⁠> f a -⁠> f a` Returns the result of appending the first argument to the second. @@ -2235,7 +2268,7 @@ Just ([1]) Just ([1, 2, 3]) ``` -#### `prepend :: (Applicative f, Semigroup (f a)) => a -⁠> f a -⁠> f a` +#### `prepend :: (Applicative f, Semigroup (f a)) => a -⁠> f a -⁠> f a` Returns the result of prepending the first argument to the second. @@ -2255,7 +2288,7 @@ Just ([1]) Just ([1, 2, 3]) ``` -#### `joinWith :: String -⁠> Array String -⁠> String` +#### `joinWith :: String -⁠> Array String -⁠> String` Joins the strings of the second argument separated by the first argument. @@ -2271,7 +2304,7 @@ See also [`splitOn`](#splitOn). 'foo:bar:baz' ``` -#### `elem :: (Setoid a, Foldable f) => a -⁠> f a -⁠> Boolean` +#### `elem :: (Setoid a, Foldable f) => a -⁠> f a -⁠> Boolean` Takes a value and a structure and returns `true` [iff][] the value is an element of the structure. @@ -2301,7 +2334,7 @@ false false ``` -#### `find :: Foldable f => (a -⁠> Boolean) -⁠> f a -⁠> Maybe a` +#### `find :: Foldable f => (a -⁠> Boolean) -⁠> f a -⁠> Maybe a` Takes a predicate and a structure and returns Just the leftmost element of the structure which satisfies the predicate; Nothing if there is no @@ -2317,7 +2350,7 @@ Just (-2) Nothing ``` -#### `foldMap :: (Monoid m, Foldable f) => TypeRep m -⁠> (a -⁠> m) -⁠> f a -⁠> m` +#### `foldMap :: (Monoid m, Foldable f) => TypeRep m -⁠> (a -⁠> m) -⁠> f a -⁠> m` Curried version of [`Z.foldMap`][]. Deconstructs a foldable by mapping every element to a monoid and concatenating the results. @@ -2330,7 +2363,7 @@ every element to a monoid and concatenating the results. [11, 12, 21, 22, 31, 32] ``` -#### `unfoldr :: (b -⁠> Maybe (Pair a b)) -⁠> b -⁠> Array a` +#### `unfoldr :: (b -⁠> Maybe (Pair a b)) -⁠> b -⁠> Array a` Takes a function and a seed value, and returns an array generated by applying the function repeatedly. The array is initially empty. The @@ -2347,7 +2380,7 @@ of the function should result in either: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] ``` -#### `range :: Integer -⁠> Integer -⁠> Array Integer` +#### `range :: Integer -⁠> Integer -⁠> Array Integer` Returns an array of consecutive integers starting with the first argument and ending with the second argument minus one. Returns `[]` if the second @@ -2364,7 +2397,7 @@ argument is less than or equal to the first argument. [] ``` -#### `groupBy :: (a -⁠> a -⁠> Boolean) -⁠> Array a -⁠> Array (Array a)` +#### `groupBy :: (a -⁠> a -⁠> Boolean) -⁠> Array a -⁠> Array (Array a)` Splits its array argument into an array of arrays of equal, adjacent elements. Equality is determined by the function @@ -2385,7 +2418,7 @@ Properties: [[2], [-3, 3, 3, 3], [4, -4], [4]] ``` -#### `reverse :: (Applicative f, Foldable f, Monoid (f a)) => f a -⁠> f a` +#### `reverse :: (Applicative f, Foldable f, Monoid (f a)) => f a -⁠> f a` Reverses the elements of the given structure. @@ -2400,7 +2433,7 @@ Cons (3) (Cons (2) (Cons (1) (Nil))) 'cba' ``` -#### `sort :: (Ord a, Applicative m, Foldable m, Monoid (m a)) => m a -⁠> m a` +#### `sort :: (Ord a, Applicative m, Foldable m, Monoid (m a)) => m a -⁠> m a` Performs a [stable sort][] of the elements of the given structure, using [`Z.lte`][] for comparisons. @@ -2419,7 +2452,7 @@ See also [`sortBy`](#sortBy). [Left (2), Left (4), Right (1), Right (3)] ``` -#### `sortBy :: (Ord b, Applicative m, Foldable m, Monoid (m a)) => (a -⁠> b) -⁠> m a -⁠> m a` +#### `sortBy :: (Ord b, Applicative m, Foldable m, Monoid (m a)) => (a -⁠> b) -⁠> m a -⁠> m a` Performs a [stable sort][] of the elements of the given structure, using [`Z.lte`][] to compare the values produced by applying the given function @@ -2462,7 +2495,7 @@ If descending order is desired, one may use [`Descending`][]: [121, 117, 116, 114, 110, 99, 97, 97, 83] ``` -#### `zip :: Array a -⁠> Array b -⁠> Array (Pair a b)` +#### `zip :: Array a -⁠> Array b -⁠> Array (Pair a b)` Returns an array of pairs of corresponding elements from the given arrays. The length of the resulting array is equal to the length of @@ -2478,7 +2511,7 @@ See also [`zipWith`](#zipWith). [Pair (1) (2), Pair (3) (4)] ``` -#### `zipWith :: (a -⁠> b -⁠> c) -⁠> Array a -⁠> Array b -⁠> Array c` +#### `zipWith :: (a -⁠> b -⁠> c) -⁠> Array a -⁠> Array b -⁠> Array c` Returns the result of combining, pairwise, the given arrays using the given binary function. The length of the resulting array is equal to the @@ -2496,20 +2529,21 @@ See also [`zip`](#zip). ### Object -#### `prop :: String -⁠> a -⁠> b` +#### `prop :: String -⁠> a -⁠> b` Takes a property name and an object with known properties and returns the value of the specified property. If for some reason the object lacks the specified property, a type error is thrown. For accessing properties of uncertain objects, use [`get`](#get) instead. +For accessing string map values by key, use [`value`](#value) instead. ```javascript > S.prop ('a') ({a: 1, b: 2}) 1 ``` -#### `props :: Array String -⁠> a -⁠> b` +#### `props :: Array String -⁠> a -⁠> b` Takes a property path (an array of property names) and an object with known structure and returns the value at the given path. If for some @@ -2523,13 +2557,13 @@ instead. 1 ``` -#### `get :: (Any -⁠> Boolean) -⁠> String -⁠> a -⁠> Maybe b` +#### `get :: (Any -⁠> Boolean) -⁠> String -⁠> a -⁠> Maybe b` Takes a predicate, a property name, and an object and returns Just the value of the specified object property if it exists and the value satisfies the given predicate; Nothing otherwise. -See also [`gets`](#gets) and [`prop`](#prop). +See also [`gets`](#gets), [`prop`](#prop), and [`value`](#value). ```javascript > S.get (S.is ($.Number)) ('x') ({x: 1, y: 2}) @@ -2548,7 +2582,7 @@ Just ([1, 2, 3]) Nothing ``` -#### `gets :: (Any -⁠> Boolean) -⁠> Array String -⁠> a -⁠> Maybe b` +#### `gets :: (Any -⁠> Boolean) -⁠> Array String -⁠> a -⁠> Maybe b` Takes a predicate, a property path (an array of property names), and an object and returns Just the value at the given path if such a path @@ -2575,7 +2609,27 @@ the same type. Formally, a value is a member of type `StrMap a` if its [type identifier][] is `'Object'` and the values of its enumerable own properties are all members of type `a`. -#### `singleton :: String -⁠> a -⁠> StrMap a` +#### `value :: String -⁠> StrMap a -⁠> Maybe a` + +Retrieve the value associated with the given key in the given string map. + +Formally, `value (k) (m)` evaluates to `Just (m[k])` if `k` is an +enumerable own property of `m`; `Nothing` otherwise. + +See also [`prop`](#prop) and [`get`](#get). + +```javascript +> S.value ('foo') ({foo: 1, bar: 2}) +Just (1) + +> S.value ('bar') ({foo: 1, bar: 2}) +Just (2) + +> S.value ('baz') ({foo: 1, bar: 2}) +Nothing +``` + +#### `singleton :: String -⁠> a -⁠> StrMap a` Takes a string and a value of any type, and returns a string map with a single entry (mapping the key to the value). @@ -2585,7 +2639,7 @@ a single entry (mapping the key to the value). {foo: 42} ``` -#### `insert :: String -⁠> a -⁠> StrMap a -⁠> StrMap a` +#### `insert :: String -⁠> a -⁠> StrMap a -⁠> StrMap a` Takes a string, a value of any type, and a string map, and returns a string map comprising all the entries of the given string map plus the @@ -2602,7 +2656,7 @@ function. {a: 4, b: 2} ``` -#### `remove :: String -⁠> StrMap a -⁠> StrMap a` +#### `remove :: String -⁠> StrMap a -⁠> StrMap a` Takes a string and a string map, and returns a string map comprising all the entries of the given string map except the one whose key matches the @@ -2619,7 +2673,7 @@ function. {} ``` -#### `keys :: StrMap a -⁠> Array String` +#### `keys :: StrMap a -⁠> Array String` Returns the keys of the given string map, in arbitrary order. @@ -2628,7 +2682,7 @@ Returns the keys of the given string map, in arbitrary order. ['a', 'b', 'c'] ``` -#### `values :: StrMap a -⁠> Array a` +#### `values :: StrMap a -⁠> Array a` Returns the values of the given string map, in arbitrary order. @@ -2637,7 +2691,7 @@ Returns the values of the given string map, in arbitrary order. [1, 2, 3] ``` -#### `pairs :: StrMap a -⁠> Array (Pair String a)` +#### `pairs :: StrMap a -⁠> Array (Pair String a)` Returns the key–value pairs of the given string map, in arbitrary order. @@ -2646,7 +2700,7 @@ Returns the key–value pairs of the given string map, in arbitrary order. [Pair ('a') (1), Pair ('b') (2), Pair ('c') (3)] ``` -#### `fromPairs :: Foldable f => f (Pair String a) -⁠> StrMap a` +#### `fromPairs :: Foldable f => f (Pair String a) -⁠> StrMap a` Returns a string map containing the key–value pairs specified by the given [Foldable][]. If a key appears in multiple pairs, the rightmost @@ -2662,7 +2716,7 @@ pair takes precedence. ### Number -#### `negate :: ValidNumber -⁠> ValidNumber` +#### `negate :: ValidNumber -⁠> ValidNumber` Negates its argument. @@ -2674,7 +2728,7 @@ Negates its argument. 42 ``` -#### `add :: FiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` +#### `add :: FiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` Returns the sum of two (finite) numbers. @@ -2683,7 +2737,7 @@ Returns the sum of two (finite) numbers. 2 ``` -#### `sum :: Foldable f => f FiniteNumber -⁠> FiniteNumber` +#### `sum :: Foldable f => f FiniteNumber -⁠> FiniteNumber` Returns the sum of the given array of (finite) numbers. @@ -2701,7 +2755,7 @@ Returns the sum of the given array of (finite) numbers. 0 ``` -#### `sub :: FiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` +#### `sub :: FiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` Takes a finite number `n` and returns the _subtract `n`_ function. @@ -2710,7 +2764,7 @@ Takes a finite number `n` and returns the _subtract `n`_ function. [0, 1, 2] ``` -#### `mult :: FiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` +#### `mult :: FiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` Returns the product of two (finite) numbers. @@ -2719,7 +2773,7 @@ Returns the product of two (finite) numbers. 8 ``` -#### `product :: Foldable f => f FiniteNumber -⁠> FiniteNumber` +#### `product :: Foldable f => f FiniteNumber -⁠> FiniteNumber` Returns the product of the given array of (finite) numbers. @@ -2737,7 +2791,7 @@ Returns the product of the given array of (finite) numbers. 1 ``` -#### `div :: NonZeroFiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` +#### `div :: NonZeroFiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` Takes a non-zero finite number `n` and returns the _divide by `n`_ function. @@ -2747,7 +2801,7 @@ function. [0, 0.5, 1, 1.5] ``` -#### `pow :: FiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` +#### `pow :: FiniteNumber -⁠> FiniteNumber -⁠> FiniteNumber` Takes a finite number `n` and returns the _power of `n`_ function. @@ -2759,7 +2813,7 @@ Takes a finite number `n` and returns the _power of `n`_ function. [1, 2, 3, 4, 5] ``` -#### `mean :: Foldable f => f FiniteNumber -⁠> Maybe FiniteNumber` +#### `mean :: Foldable f => f FiniteNumber -⁠> Maybe FiniteNumber` Returns the mean of the given array of (finite) numbers. @@ -2779,7 +2833,7 @@ Nothing ### Integer -#### `even :: Integer -⁠> Boolean` +#### `even :: Integer -⁠> Boolean` Returns `true` if the given integer is even; `false` if it is odd. @@ -2791,7 +2845,7 @@ true false ``` -#### `odd :: Integer -⁠> Boolean` +#### `odd :: Integer -⁠> Boolean` Returns `true` if the given integer is odd; `false` if it is even. @@ -2805,7 +2859,7 @@ false ### Parse -#### `parseDate :: String -⁠> Maybe ValidDate` +#### `parseDate :: String -⁠> Maybe ValidDate` Takes a string `s` and returns `Just (new Date (s))` if `new Date (s)` evaluates to a [`ValidDate`][ValidDate] value; Nothing otherwise. @@ -2814,7 +2868,7 @@ As noted in [#488][], this function's behaviour is unspecified for some inputs! [MDN][date parsing] warns against using the `Date` constructor to parse date strings: -> __Note:__ parsing of date strings with the `Date` constructor \[…] is +> __Note:__ parsing of date strings with the `Date` constructor […] is > strongly discouraged due to browser differences and inconsistencies. > Support for RFC 2822 format strings is by convention only. Support for > ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") @@ -2828,7 +2882,7 @@ Just (new Date ('2011-01-19T17:40:00.000Z')) Nothing ``` -#### `parseFloat :: String -⁠> Maybe Number` +#### `parseFloat :: String -⁠> Maybe Number` Takes a string and returns Just the number represented by the string if it does in fact represent a number; Nothing otherwise. @@ -2841,7 +2895,7 @@ Just (-123.45) Nothing ``` -#### `parseInt :: Radix -⁠> String -⁠> Maybe Integer` +#### `parseInt :: Radix -⁠> String -⁠> Maybe Integer` Takes a radix (an integer between 2 and 36 inclusive) and a string, and returns Just the number represented by the string if it does in @@ -2863,7 +2917,7 @@ Just (255) Nothing ``` -#### `parseJson :: (Any -⁠> Boolean) -⁠> String -⁠> Maybe a` +#### `parseJson :: (Any -⁠> Boolean) -⁠> String -⁠> Maybe a` Takes a predicate and a string which may or may not be valid JSON, and returns Just the result of applying `JSON.parse` to the string *if* the @@ -2885,7 +2939,7 @@ Just ([1, 2, 3]) ### RegExp -#### `regex :: RegexFlags -⁠> String -⁠> RegExp` +#### `regex :: RegexFlags -⁠> String -⁠> RegExp` Takes a [RegexFlags][] and a pattern, and returns a RegExp. @@ -2894,7 +2948,7 @@ Takes a [RegexFlags][] and a pattern, and returns a RegExp. /:\d+:/g ``` -#### `regexEscape :: String -⁠> String` +#### `regexEscape :: String -⁠> String` Takes a string which may contain regular expression metacharacters, and returns a string with those metacharacters escaped. @@ -2909,7 +2963,7 @@ Properties: '\\-=\\*\\{XYZ\\}\\*=\\-' ``` -#### `test :: RegExp -⁠> String -⁠> Boolean` +#### `test :: RegExp -⁠> String -⁠> Boolean` Takes a pattern and a string, and returns `true` [iff][] the pattern matches the string. @@ -2922,7 +2976,7 @@ true false ``` -#### `match :: NonGlobalRegExp -⁠> String -⁠> Maybe { match :: String, groups :: Array (Maybe String) }` +#### `match :: NonGlobalRegExp -⁠> String -⁠> Maybe { match :: String, groups :: Array (Maybe String) }` Takes a pattern and a string, and returns Just a match record if the pattern matches the string; Nothing otherwise. @@ -2946,7 +3000,7 @@ Just ({match: 'goodbye', groups: [Just ('good')]}) Just ({match: 'bye', groups: [Nothing]}) ``` -#### `matchAll :: GlobalRegExp -⁠> String -⁠> Array { match :: String, groups :: Array (Maybe String) }` +#### `matchAll :: GlobalRegExp -⁠> String -⁠> Array { match :: String, groups :: Array (Maybe String) }` Takes a pattern and a string, and returns an array of match records. @@ -2967,7 +3021,7 @@ See also [`match`](#match). ### String -#### `toUpper :: String -⁠> String` +#### `toUpper :: String -⁠> String` Returns the upper-case equivalent of its argument. @@ -2978,7 +3032,7 @@ See also [`toLower`](#toLower). 'ABC DEF 123' ``` -#### `toLower :: String -⁠> String` +#### `toLower :: String -⁠> String` Returns the lower-case equivalent of its argument. @@ -2989,7 +3043,7 @@ See also [`toUpper`](#toUpper). 'abc def 123' ``` -#### `trim :: String -⁠> String` +#### `trim :: String -⁠> String` Strips leading and trailing whitespace characters. @@ -2998,7 +3052,7 @@ Strips leading and trailing whitespace characters. 'foo bar' ``` -#### `stripPrefix :: String -⁠> String -⁠> Maybe String` +#### `stripPrefix :: String -⁠> String -⁠> Maybe String` Returns Just the portion of the given string (the second argument) left after removing the given prefix (the first argument) if the string starts @@ -3014,7 +3068,7 @@ Just ('sanctuary.js.org') Nothing ``` -#### `stripSuffix :: String -⁠> String -⁠> Maybe String` +#### `stripSuffix :: String -⁠> String -⁠> Maybe String` Returns Just the portion of the given string (the second argument) left after removing the given suffix (the first argument) if the string ends @@ -3030,7 +3084,7 @@ Just ('README') Nothing ``` -#### `words :: String -⁠> Array String` +#### `words :: String -⁠> Array String` Takes a string and returns the array of words the string contains (words are delimited by whitespace characters). @@ -3042,7 +3096,7 @@ See also [`unwords`](#unwords). ['foo', 'bar', 'baz'] ``` -#### `unwords :: Array String -⁠> String` +#### `unwords :: Array String -⁠> String` Takes an array of words and returns the result of joining the words with separating spaces. @@ -3054,7 +3108,7 @@ See also [`words`](#words). 'foo bar baz' ``` -#### `lines :: String -⁠> Array String` +#### `lines :: String -⁠> Array String` Takes a string and returns the array of lines the string contains (lines are delimited by newlines: `'\n'` or `'\r\n'` or `'\r'`). @@ -3067,7 +3121,7 @@ See also [`unlines`](#unlines). ['foo', 'bar', 'baz'] ``` -#### `unlines :: Array String -⁠> String` +#### `unlines :: Array String -⁠> String` Takes an array of lines and returns the result of joining the lines after appending a terminating line feed (`'\n'`) to each. @@ -3079,7 +3133,7 @@ See also [`lines`](#lines). 'foo\nbar\nbaz\n' ``` -#### `splitOn :: String -⁠> String -⁠> Array String` +#### `splitOn :: String -⁠> String -⁠> Array String` Returns the substrings of its second argument separated by occurrences of its first argument. @@ -3091,7 +3145,7 @@ See also [`joinWith`](#joinWith) and [`splitOnRegex`](#splitOnRegex). ['foo', 'bar', 'baz'] ``` -#### `splitOnRegex :: GlobalRegExp -⁠> String -⁠> Array String` +#### `splitOnRegex :: GlobalRegExp -⁠> String -⁠> Array String` Takes a pattern and a string, and returns the result of splitting the string at every non-overlapping occurrence of the pattern. diff --git a/package.json b/package.json index 20f5f064..97b8a213 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sanctuary", - "version": "1.0.0", + "version": "1.1.0", "description": "Refuge from unsafe JavaScript", "license": "MIT", "repository": {