basic examples
This commit is contained in:
@@ -118,3 +118,9 @@ data FatalError = FatalError {msg :: Text}
|
|||||||
```haskell
|
```haskell
|
||||||
panic :: Text -> a
|
panic :: Text -> a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Terminate with an uncatchable fatal error.
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
> panic "Fatal error occured.
|
||||||
|
```
|
||||||
|
|||||||
@@ -10,32 +10,66 @@ Composition
|
|||||||
($) :: (a -> b) -> a -> b
|
($) :: (a -> b) -> a -> b
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Infix form of function application. Applies a function from ``a → b`` to an
|
||||||
|
argument ``a``.
|
||||||
|
|
||||||
*Example*:
|
*Example*:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
> take 2 $ [1,2,3]
|
||||||
|
[1,2]
|
||||||
|
```
|
||||||
|
|
||||||
#### .
|
#### .
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
(.) :: (b -> c) -> (a -> b) -> a -> c
|
(.) :: (b -> c) -> (a -> b) -> a -> c
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Function composition. Composes a function ``f`` (``b → c``) with a function
|
||||||
|
``g`` (``a → b``) yielding ``f ∘ g``.
|
||||||
|
|
||||||
*Example*:
|
*Example*:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
> map (negate . abs) [-1,0,1]
|
||||||
|
[-1,0,-1]
|
||||||
|
```
|
||||||
|
|
||||||
#### &
|
#### &
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
(&) :: a -> (a -> b) -> b
|
(&) :: a -> (a -> b) -> b
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Flipped form of ``($)`` which applies an argument ``a`` to a function ``a → b``.
|
||||||
|
|
||||||
*Example*:
|
*Example*:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
> [1,2,3] & take 2
|
||||||
|
[1,2]
|
||||||
|
|
||||||
|
> replicate 10 3 & take 5 & tail
|
||||||
|
[3,3,3,3]
|
||||||
|
```
|
||||||
|
|
||||||
#### flip
|
#### flip
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
flip :: (a -> b -> c) -> b -> a -> c
|
flip :: (a -> b -> c) -> b -> a -> c
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Flip takes a function of two arguments and returns a function taking the them in
|
||||||
|
reverse order.
|
||||||
|
|
||||||
*Example*:
|
*Example*:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
λ> flip take [1,2,3] 2
|
||||||
|
[1,2]
|
||||||
|
```
|
||||||
|
|
||||||
#### on
|
#### on
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
@@ -44,6 +78,11 @@ on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
|
|||||||
|
|
||||||
*Example*:
|
*Example*:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
> sortBy (compare `on` fst) [(1,2), (3,4), (0,1)]
|
||||||
|
[(0,1),(1,2),(3,4)]
|
||||||
|
```
|
||||||
|
|
||||||
#### const
|
#### const
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name: protolude
|
name: protolude
|
||||||
version: 0.1.11
|
version: 0.2
|
||||||
synopsis: A sensible set of defaults for writing custom Preludes.
|
synopsis: A sensible set of defaults for writing custom Preludes.
|
||||||
description: A sensible set of defaults for writing custom Preludes.
|
description: A sensible set of defaults for writing custom Preludes.
|
||||||
homepage: https://github.com/sdiehl/protolude
|
homepage: https://github.com/sdiehl/protolude
|
||||||
|
|||||||
Reference in New Issue
Block a user