Skip to content

Commit

Permalink
more explanation for the map-f-l pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd committed Nov 9, 2013
1 parent 4db27d4 commit acb6319
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ l = map ((^)2) [1..10]
```

Sure, what is more readable/pretty is also a matter or habit/taste. But
beside the terseness there come other benefits with this abstraction,
e.g. if you want to decide from the outside what to do with the values:
beside the terseness there come other benefits with the abstract separation
of the control structure, e.g. if you want to decide from the outside what
to do with the values:

```haskell
l1 = buildPairs [1..5] ((^)2)
Expand All @@ -106,8 +107,8 @@ l4 = buildPairs [1..5] ((+)1)

You can also decide which direction you prefer to read:
```haskell
la = map ((^)2) [1..10] -- normal function application
lb = ((^)2) `map` [1..10] -- infix notation
la = map ((^)2) [1..10] -- normal function application
lb = ((^)2) `map` [1..10] -- infix notation
lc = [1..10] |> map ((^)2) -- forward application
```

Expand Down

0 comments on commit acb6319

Please sign in to comment.