any package:base

Determines whether any element of the structure satisfies the predicate.

Examples

Basic usage:
>>> any (> 3) []
False
>>> any (> 3) [1,2]
False
>>> any (> 3) [1,2,3,4,5]
True
>>> any (> 3) [1..]
True
>>> any (> 3) [0, -1..]
* Hangs forever *
Applied to a predicate and a list, any determines if any element of the list satisfies the predicate. For the result to be False, the list must be finite; True, however, results from a True value for the predicate applied to an element at a finite index of a finite or infinite list.

Examples

>>> any (> 3) []
False
>>> any (> 3) [1,2]
False
>>> any (> 3) [1,2,3,4,5]
True
>>> any (> 3) [1..]
True
>>> any (> 3) [0, -1..]
* Hangs forever *
Boolean monoid under disjunction (||).
Any x <> Any y = Any (x || y)

Examples

>>> Any True <> mempty <> Any False
Any {getAny = True}
>>> mconcat (map (\x -> Any (even x)) [2,4,6,7,8])
Any {getAny = True}
>>> Any False <> mempty
Any {getAny = False}
The type constructor Any :: forall k. k is a type to which you can unsafely coerce any type, and back. For unsafeCoerce this means for all lifted types t that unsafeCoerce (unsafeCoerce x :: Any) :: t is equivalent to x and safe. The same is true for *all* types when using unsafeCoerce# :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep) (a :: TYPE r1) (b :: TYPE r2). a -> b but only if you instantiate r1 and r2 to the same runtime representation. For example using (unsafeCoerce# :: forall (a :: TYPE IntRep) (b :: TYPE IntRep). a -> b) x is fine, but (unsafeCoerce# :: forall (a :: TYPE IntRep) (b :: TYPE FloatRep). a -> b) will likely cause seg-faults or worse. For this resason, users should always prefer unsafeCoerce over unsafeCoerce# when possible. Here are some more examples: bad_a1 :: Any (TYPE 'IntRep) bad_a1 = unsafeCoerce# True bad_a2 :: Any (TYPE ('BoxedRep 'UnliftedRep)) bad_a2 = unsafeCoerce# True Here bad_a1 is bad because we started with True :: (Bool :: Type), represented by a boxed heap pointer, and coerced it to a1 :: Any (TYPE 'IntRep), whose representation is a non-pointer integer. That's why we had to use unsafeCoerce#; it is really unsafe because it can change representations. Similarly bad_a2 is bad because although both True and bad_a2 are represented by a heap pointer, True is lifted but bad_a2@ is not; bugs here may be rather subtle. If you must use unsafeCoerce# to cast to Any, type annotations are recommended to make sure that Any has the correct kind. As casting between different runtimereps is unsound. For example to cast a ByteArray# to Any you might use: unsafeCoerce# b :: (Any :: TYPE ('BoxedRep 'Unlifted))
Retrieve the address of any Haskell value. This is essentially an unsafeCoerce#, but if implemented as such the core lint pass complains and fails to compile. As a primop, it is opaque to core/stg, and only appears in cmm (where the copy propagation pass will get rid of it). Note that "a" must be a value, not a thunk! It's too late for strictness analysis to enforce this, so you're on your own to guarantee this. Also note that Addr# is not a GC pointer - up to you to guarantee that it does not become a dangling pointer immediately after you get it.
Zero or more.

Examples

>>> many (putStr "la")
lalalalalalalalala... * goes on forever *
>>> many Nothing
Just []
>>> take 5 <$> many (Just 1)
* hangs forever *
Note that this function can be used with Parsers based on Applicatives. In that case many parser will attempt to parse parser zero or more times until it fails.
Determines whether any element of the structure satisfies its appropriate predicate argument. Empty structures yield False.

Examples

Basic usage:
>>> biany even isDigit (27, 't')
False
>>> biany even isDigit (27, '8')
True
>>> biany even isDigit (26, 't')
True
>>> biany even isDigit (Left 27)
False
>>> biany even isDigit (Left 26)
True
>>> biany even isDigit (BiList [27, 53] ['t', '8'])
True
Empty structures yield False:
>>> biany even isDigit (BiList [] [])
False
Replicates a withXXX combinator over a list of objects, yielding a list of marshalled objects
Parses zero or more occurrences of the given parser.
Parses one or more occurrences of the given parser.
manyTill p end parses zero or more occurrences of p, until end succeeds. Returns a list of values returned by p.
Like many, but discards the result.
Like many1, but discards the result.
Returns 1# if the object is in any CNF at all, 0# otherwise.
Catch any Exception type in the IO monad. Note that this function is strict in the action. That is, catchAny undefined b == _|_. See for details. If you rethrow an exception, you should reuse the supplied ExceptionContext.