Unit 9 - Functional Approaches - Comprehensions, Lambda, Closures And Higher-Order Functions

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

What Is A Pure Function?

  • A function whose return value depends only on its arguments, with no side effects

  • Actions that affect the external state of a program, such as modifying a global variable or performing I/O

2
New cards

What Is The Primary Advantage Of Immutable Data Structures?

They prevent unexpected changes to values, eliminating aliasing issues and making code easier to reason about

3
New cards

What is a list comprehension?

A concise way to create lists by applying an expression to each element of a sequence, optionally filtering elements

4
New cards

What is the difference between using if at the end of a comprehension versus within the expression part?

At the end, if acts as a filter, removing elements - within the expression, it conditionally evaluates to one of two values for each element, without changing the number of elements

5
New cards

What is a closure?

A function that “closes over” variables from its enclosing scope, remembering them even after the outer function has finished executing

6
New cards

What is reduce used for?

To apply a two-argument function cumulatively to the items of a sequence, reducing it to a single value

7
New cards

What does zip do?

It takes multiple sequences and returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the input sequences

8
New cards

What is a lambda expression?

An anonymous function defined using the lambda keyword, typically used for short, one-off functions within an expression

9
New cards

What is recursion essential in pure functional programming?

Because pure functional programming avoids mutable variables and loops, recursion is the primary mechanism for repeating operations

10
New cards

Data Flow Model

Functions are nodes, data as edges - powers parallel systems

11
New cards

nonlocal Purpose

Modify a variable in an outer (non-global) scope from within a nested function

12
New cards

Recursive Function Structure

  • Base Case: Trivial solution, stops recursion

  • Recursive Step: Call itself with modified args, moving towards base case