You got it, pretty much. So the rest of the deal is designing the predicate function for your list. Assuming you already had a list called xs and a predicate function p, all you’d have to do is
filter p xs.
Often, you’ll see p defined as an anonymous, or lambda, expression, like so:
filter (\n -> n \`mod\` 2 == 0) xs.
It is not necessary, and it might be helpful as a beginner to define named functions.
isEven n = n \`mod\` 2 == 0 evenListNumbers xs = filter isEven xs evenListNumbers [1,2,3,4]
Which is this [2,4]
.
So a predicate function for a given list filter takes a list element and returns a boolean value. If it’s true, the element is retained (or added to the resulting list), and if it’s false, it is passed over.
Related Posts:
- strdup() – what does it do in C?
- strdup() – what does it do in C?
- “Parameter” vs “Argument”
- What is the proper declaration of main in C++?
- ‘foo’ was not declared in this scope c++
- Help needed with Median If in Excel
- PHP Fatal error: Using $this when not in object context
- Haskell pattern matching – what is it?
- How do you pass a function as a parameter in C?
- How do you pass a function as a parameter in C?
- Using multiple .cpp files in c++ program?
- Optional arguments in C function
- the functions (procedures) in MIPS
- C: How do I make a number always round up
- How to send an email with Python?
- C++ — expected primary-expression before ‘ ‘
- Define a global variable in a JavaScript function
- Cannot read property ‘addEventListener’ of null
- Return array in a function
- Meaning of = delete after function declaration
- How do I define a function with optional arguments?
- Basic explanation of python functions
- What’s the difference between a method and a function?
- Deprecated: mysql_connect()
- C error: undefined reference to function, but it IS defined
- Call a function from another file?
- invalid use of non-static member function
- Reverse Contents in Array
- What is the best way to exit a function (which has no return value) in python before the function ends (e.g. a check fails)?
- c++: No instance of overloaded function
- Apply function to each element of a list
- error: expected primary-expression before ‘)’ token (C)
- Return value in a Bash function
- How do you pass a function as a parameter in C?
- error: “initializer expression list treated as compound expression”
- Getting error: ISO C++ forbids declaration of with no type
- Pass a JavaScript function as parameter
- IsNumeric function in c#
- Using map in Haskell
- How to stop a function
- Difference between return and exit in Bash functions
- includes() not working in all browsers
- Haskell – parse error on input `|’
- Repeating a function in Python
- Uncaught TypeError: .indexOf is not a function
- How to get a function name as a string?
- Anagrams finder in javascript
- How to return a result from a VBA function
- Python: Can a function return an array and a variable?
- Php include not working? function not being included
- c++ –
- Why is the minimalist, example Haskell quicksort not a “true” quicksort?
- jquery – is not a function error
- Can you write nested functions in JavaScript?
- Simple average function in Javascript
- What does it mean that “a declaration shadows a parameter”?
- C++ – statement cannot resolve address for overloaded function
- Calling a user defined function in jQuery
- How to add an object to an array
- Error haskell: not in scope. What does that mean?
- How to return a boolean method in java?
- Is there a math nCr function in python?
- What is define([ , function ]) in JavaScript?
- How to return a struct from a function in C++?
- Why can’t we pass arrays to function by value?
- Stopping a JavaScript function when a certain condition is met
- absolute values in Haskell
- template argument deduction/substitution failed, when using std::function and std::bind
- Can I define a function inside a C structure?
- Simplest/cleanest way to implement a singleton in JavaScript
- Create a function with optional call variables
- Return array from function
- Passing string to a function in C – with or without pointers?
- What is the difference between ggplot and ggplot2?
- Javascript call() & apply() vs bind()?
- Parameter name omitted error?
- Adding +1 to a variable inside a function
- ERROR: Control may reach end of non-void function /
- Reverse a list in haskell
- function does not take 1 arguments c++
- JavaScript button onclick not working
- JavaScript button onclick not working
- warning: return makes pointer from integer without a cast but returns integer as desired
- Is there a math nCr function in python? [duplicate]
- Haskell Merge Sort
- Difference between function arguments declared with & and * in C++
- What is the meaning of the dollar sign “$” in R function()?
- Difference between `mod` and `rem` in Haskell
- How to fix “variable not in scope” error in GHCI?
- Is C++ Array passed by reference or by pointer?
- “cannot be used as a function error”
- How to run a PHP function from an HTML form?
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade
- Division in Haskell
- $http.get(…).success is not a function
- What does the “Just” syntax mean in Haskell?
- Run function from the command line
- How to split a string in Haskell?
- How can you use php in a javascript function
- change homepage for logged-in users in wordpress