Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed typos in closures playground #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions 7. Closures.playground/section-1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// are a special case of closures.
//
// * Closures of all types (including nested functions) employ a method of capturing the surrounding
// context in which is is defined, allowing it to access constants and variables from that
// context in which it is defined, allowing it to access constants and variables from that
// context.
// ------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -65,11 +65,11 @@ reversed = names.sorted({
})

// Since all types can be inferred and we're not using any type annotation on the parameters,
// we can simplify a bit further by removing the paranthesis around the parameters. We'll also put
// we can simplify a bit further by removing the parenthesis around the parameters. We'll also put
// it all on a single line, since it's a bit more clear now:
reversed = names.sorted({ s1, s2 in return s1 > s2 })

// If the closuere has only a single expression, then the return statement is also inferred. When
// If the closure has only a single expression, then the return statement is also inferred. When
// this is the case, the closure returns the value of the single expression:
reversed = names.sorted({ s1, s2 in s1 > s2 })

Expand Down Expand Up @@ -121,7 +121,7 @@ reversed = names.sorted {
}

// Note that the opening brace for the closure must be on the same line as the function call's
// ending paranthesis. This is the same functinon call with the starting brace for the closure
// ending parenthesis. This is the same function call with the starting brace for the closure
// moved to the next line. This will not compile:
//
// reversed = sort(names)
Expand All @@ -146,7 +146,7 @@ func returnValue(f: () -> Int) -> Int
returnValue {return 6}

// And if we apply the simplification described earlier that implies the return statement for
// single-expresssion closures, it simplifies to this oddly-looking line of code:
// single-expression closures, it simplifies to this oddly-looking line of code:
returnValue {6}

// ------------------------------------------------------------------------------------------------
Expand All @@ -155,7 +155,7 @@ returnValue {6}
// The idea of capturing is to allow a closure to access the variables and constants in their
// surrounding context.
//
// For example, a nested function can access contstans and variables from the function in which
// For example, a nested function can access constants and variables from the function in which
// it is defined. If this nested function is returned, each time it is called, it will work within
// that "captured" context.
//
Expand Down Expand Up @@ -196,7 +196,7 @@ incrementBy10() // returns 30
var copyIncrementBy10 = incrementBy10
copyIncrementBy10() // returns 40

// If we request a new incremntor that increments by 10, it will have a separate and unique captured
// If we request a new incrementor that increments by 10, it will have a separate and unique captured
// context:
var anotherIncrementBy10 = makeIncrementor(forIncrement: 10)
anotherIncrementBy10() // returns 10
Expand Down