Login
|
Signup
langref.org
-
python
,
clojure
, and
fsharp
add..
all
cpp
csharp
erlang
fantom
go
groovy
haskell
java
ocaml
perl
php
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Lists
Testing
Test if a condition holds for any items of a list
Given a list, test if a certain logical condition (i.e. predicate) holds for any items of the list.
python
2.6
any(x > 3 for x in [2, 3, 4])
any(x > 3 for x in [2, 3, 4])
clojure
; The standard library in Clojure has "not-any?" but (oddly enough) no "any?"
(defn any? [pred coll]
((complement not-any?) pred coll))
(any? #(> % 3) [2 3 4])
; The standard library in Clojure has "not-any?" but (oddly enough) no "any?"
(defn any? [pred coll]
((complement not-any?) pred coll))
(any? #(> % 3) [2 3 4])
clojure
(some #(> % 3) [2 3 4])
(some #(> % 3) [2 3 4])
fsharp
fsharp
let rec IsAny predicate source =
match source with
| [] -> false
| h::t ->
if (predicate h) then true
else (IsAny predicate t )
let rec IsAny predicate source =
match source with
| [] -> false
| h::t ->
if (predicate h) then true
else (IsAny predicate t )
Submit a new solution for
python
,
clojure
, or
fsharp
There are 9 other solutions in
additional
languages (
cpp
,
erlang
,
fantom
,
groovy
...)