From 56304a9a635abeab1010234c06f490c0a6f9719b Mon Sep 17 00:00:00 2001 From: Tyson Williams Date: Thu, 18 Feb 2021 09:11:38 -0600 Subject: [PATCH 1/4] changed addPair to add2 --- content/posts/elevated-world/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/posts/elevated-world/index.md b/content/posts/elevated-world/index.md index 561c260c5..2be60c85c 100644 --- a/content/posts/elevated-world/index.md +++ b/content/posts/elevated-world/index.md @@ -528,13 +528,13 @@ First, here's an example of lifting a two-parameter function: ```fsharp // define a two-parameter function to test with -let addPair x y = x + y +let add2 x y = x + y // lift a two-param function -let addPairOpt = Option.lift2 addPair +let add2Opt = Option.lift2 add2 // call as normal -addPairOpt (Some 1) (Some 2) +add2Opt (Some 1) (Some 2) // result => Some 3 ``` From 1c3610a445fd6adbc138bb6819ba693aff910640 Mon Sep 17 00:00:00 2001 From: Tyson Williams Date: Thu, 18 Feb 2021 09:12:00 -0600 Subject: [PATCH 2/4] changed addTriple to add3 --- content/posts/elevated-world/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/posts/elevated-world/index.md b/content/posts/elevated-world/index.md index 2be60c85c..ae944fe57 100644 --- a/content/posts/elevated-world/index.md +++ b/content/posts/elevated-world/index.md @@ -542,13 +542,13 @@ And here's an example of lifting a three-parameter function: ```fsharp // define a three-parameter function to test with -let addTriple x y z = x + y + z +let add3 x y z = x + y + z // lift a three-param function -let addTripleOpt = Option.lift3 addTriple +let add3eOpt = Option.lift3 add3 // call as normal -addTripleOpt (Some 1) (Some 2) (Some 3) +add3Opt (Some 1) (Some 2) (Some 3) // result => Some 6 ``` From a015f61b26e23470253e68b00edaee4b1c96310f Mon Sep 17 00:00:00 2001 From: Tyson Williams Date: Thu, 18 Feb 2021 09:05:49 -0600 Subject: [PATCH 3/4] changed all occurrences of "tuple" to "pair" in elevated world post --- content/posts/elevated-world/index.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/content/posts/elevated-world/index.md b/content/posts/elevated-world/index.md index ae944fe57..b5870db3c 100644 --- a/content/posts/elevated-world/index.md +++ b/content/posts/elevated-world/index.md @@ -567,7 +567,7 @@ Option.lift2 (*) (Some 2) (Some 3) // Some 6 Going further, can we eliminate the need for this first function parameter and have a *generic* way of combining the values? -Why, yes we can! We can just use a tuple constructor to combine the values. +Why, yes we can! We can just use a pair constructor to combine the values. When we do this we are combining the values without making any decision about how they will be used yet. Here's what it looks like in a diagram: @@ -577,16 +577,16 @@ Here's what it looks like in a diagram: and here's how you might implement it for options and lists: ```fsharp -// define a tuple creation function -let tuple x y = x,y +// define a pair creation function +let pair x y = x,y // create a generic combiner of options -// with the tuple constructor baked in -let combineOpt x y = Option.lift2 tuple x y +// with the pair constructor baked in +let combineOpt x y = Option.lift2 pair x y // create a generic combiner of lists -// with the tuple constructor baked in -let combineList x y = List.lift2 tuple x y +// with the pair constructor baked in +let combineList x y = List.lift2 pair x y ``` Let's see what happens when we use the combiners: @@ -599,7 +599,7 @@ combineList [1;2] [100;200] // Result => [(1, 100); (1, 200); (2, 100); (2, 200)] ``` -Now that we have an elevated tuple, we can work with the pair in any way we want, we just need to use `map` to do the actual combining. +Now that we have an elevated pair, we can work with the pair in any way we want, we just need to use `map` to do the actual combining. Want to add the values? Just use `+` in the `map` function: @@ -742,7 +742,7 @@ Hence the use of `*>` to ignore the leading quote and `<*` to ignore the trailin **What it does**: Combines two lists (or other enumerables) using a specified function **Signature**: `E<(a->b->c)> -> E -> E -> E` where `E` is a list or other enumerable type, - or `E -> E -> E` for the tuple-combined version. + or `E -> E -> E` for the pair-combined version. ### Description @@ -803,7 +803,7 @@ let resultAdd = Note that we can't just have *one* `add` function in the first list -- we have to have one `add` for every element in the second and third lists! -That could get annoying, so often, a "tupled" version of `zip` is used, whereby you don't specify a combining function at all, and just get back a list of tuples instead, +That could get annoying, so often, a "paird" version of `zip` is used, whereby you don't specify a combining function at all, and just get back a list of pairs instead, which you can then process later using `map`. This is the same approach as was used in the `combine` functions discussed above, but for `zipList`. From 1bd2b87f742a023e8236258ccb1eda2e4f38dfb9 Mon Sep 17 00:00:00 2001 From: Tyson Williams <34664007+TysonMN@users.noreply.github.com> Date: Fri, 3 Dec 2021 13:19:54 -0600 Subject: [PATCH 4/4] Update content/posts/elevated-world/index.md Co-authored-by: Andrii Kurdiumov --- content/posts/elevated-world/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/posts/elevated-world/index.md b/content/posts/elevated-world/index.md index b5870db3c..aa84f710f 100644 --- a/content/posts/elevated-world/index.md +++ b/content/posts/elevated-world/index.md @@ -803,7 +803,7 @@ let resultAdd = Note that we can't just have *one* `add` function in the first list -- we have to have one `add` for every element in the second and third lists! -That could get annoying, so often, a "paird" version of `zip` is used, whereby you don't specify a combining function at all, and just get back a list of pairs instead, +That could get annoying, so often, a "paired" version of `zip` is used, whereby you don't specify a combining function at all, and just get back a list of pairs instead, which you can then process later using `map`. This is the same approach as was used in the `combine` functions discussed above, but for `zipList`.