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

Add attributes on a code block in docs in a consistent way #2348

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
40 changes: 20 additions & 20 deletions docs/User/Explanatory/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The following snippet provides a simple stream composition example that reads
numbers from stdin, prints the squares of even numbers and exits if an even
number more than 9 is entered.

``` haskell
```{.haskell}
import qualified Streamly.Prelude as S
import Data.Function ((&))

Expand Down Expand Up @@ -149,7 +149,7 @@ The following code finishes in 3 seconds (6 seconds when serial), note the
order of elements in the resulting output, the outputs are consumed as soon as
each action is finished (asyncly):

``` haskell
```{.haskell}
> let p n = threadDelay (n * 1000000) >> return n
> S.toList $ S.fromAsync $ p 3 |: p 2 |: p 1 |: S.nil
[1,2,3]
Expand All @@ -158,7 +158,7 @@ each action is finished (asyncly):
Use `fromAhead` if you want speculative concurrency i.e. execute the actions in
the stream concurrently but consume the results in the specified order:

``` haskell
```{.haskell}
> S.toList $ S.fromAhead $ p 3 |: p 2 |: p 1 |: S.nil
[3,2,1]
```
Expand All @@ -168,7 +168,7 @@ Monadic stream generation functions e.g. `unfoldrM`, `replicateM`, `repeatM`,

The following finishes in 10 seconds (100 seconds when serial):

``` haskell
```{.haskell}
S.drain $ S.fromAsync $ S.replicateM 10 $ p 10
```

Expand All @@ -179,7 +179,7 @@ following example prints a "hello" every second; if you use `&` instead of
`|&` you will see that the delay doubles to 2 seconds instead because of serial
application.

``` haskell
```{.haskell}
main = S.drain $
S.repeatM (threadDelay 1000000 >> return "hello")
|& S.mapM (\x -> threadDelay 1000000 >> putStrLn x)
Expand All @@ -189,7 +189,7 @@ main = S.drain $

We can use `mapM` or `sequence` functions concurrently on a stream.

``` haskell
```{.haskell}
> let p n = threadDelay (n * 1000000) >> return n
> S.drain $ S.fromAhead $ S.mapM (\x -> p 1 >> print x) (S.fromSerial $ S.repeatM (p 1))
```
Expand All @@ -201,7 +201,7 @@ concurrently. In the following example we compose ten actions in the
stream, each with a delay of 1 to 10 seconds, respectively. Since all the
actions are concurrent we see one output printed every second:

``` haskell
```{.haskell}
import qualified Streamly.Prelude as S
import Control.Concurrent (threadDelay)

Expand All @@ -213,7 +213,7 @@ Streams can be combined together in many ways. We provide some examples
below, see the tutorial for more ways. We use the following `delay`
function in the examples to demonstrate the concurrency aspects:

``` haskell
```{.haskell}
import qualified Streamly.Prelude as S
import Control.Concurrent

Expand All @@ -224,7 +224,7 @@ delay n = S.fromEffect $ do
```
### Serial

``` haskell
```{.haskell}
main = S.drain $ delay 3 <> delay 2 <> delay 1
```
```
Expand All @@ -235,7 +235,7 @@ ThreadId 36: Delay 1

### Parallel

``` haskell
```{.haskell}
main = S.drain . S.fromParallel $ delay 3 <> delay 2 <> delay 1
```
```
Expand All @@ -248,7 +248,7 @@ ThreadId 40: Delay 3

The monad instance composes like a list monad.

``` haskell
```{.haskell}
import qualified Streamly.Prelude as S

loops = do
Expand All @@ -271,7 +271,7 @@ To run the above code with speculative concurrency i.e. each iteration in the
loop can run concurrently but the results are presented to the consumer of the
output in the same order as serial execution:

``` haskell
```{.haskell}
main = S.drain $ S.fromAhead $ loops
```

Expand All @@ -287,7 +287,7 @@ concurrently using combinators like `fromAsync`, `parallelly`. For example,
to concurrently generate squares of a stream of numbers and then concurrently
sum the square roots of all combinations of two streams:

``` haskell
```{.haskell}
import qualified Streamly.Prelude as S

main = do
Expand All @@ -305,7 +305,7 @@ main = do
For bounded concurrent streams, stream yield rate can be specified. For
example, to print hello once every second you can simply write this:

``` haskell
```{.haskell}
import Streamly.Prelude as S

main = S.drain $ S.fromAsync $ S.avgRate 1 $ S.repeatM $ putStrLn "hello"
Expand Down Expand Up @@ -372,7 +372,7 @@ to keep them short and elegant. Source file
[CoreUtilsHandle.hs](https://github.com/composewell/streamly-examples/blob/master/examples/CoreUtilsHandle.hs)
in the examples directory includes these examples.

``` haskell
```{.haskell}
module Main where

import qualified Streamly.Prelude as S
Expand All @@ -399,28 +399,28 @@ withArg2 f = do

### cat

``` haskell
```{.haskell}
cat = S.fold (FH.writeChunks stdout) . S.unfold FH.readChunks
main = withArg cat
```

### cp

``` haskell
```{.haskell}
cp src dst = S.fold (FH.writeChunks dst) $ S.unfold FH.readChunks src
main = withArg2 cp
```

### wc -l

``` haskell
```{.haskell}
wcl = S.length . S.splitOn (== 10) FL.drain . S.unfold FH.read
main = withArg wcl >>= print
```

### Average Line Length

``` haskell
```{.haskell}
avgll =
S.fold avg
. S.splitOn (== 10) FL.length
Expand All @@ -437,7 +437,7 @@ main = withArg avgll >>= print
`classify` is not released yet, and is available in
`Streamly.Internal.Data.Fold`

``` haskell
```{.haskell}
llhisto =
S.fold (FL.classify FL.length)
. S.map bucket
Expand Down
10 changes: 5 additions & 5 deletions docs/User/Explanatory/unified-abstractions.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ API.
This simple console echo program shows the simplicity of Streamly API
and its similarity with the list API:

```haskell
```{.haskell}
echo =
Stream.repeatM getLine
& Stream.mapM putStrLn
Expand Down Expand Up @@ -110,7 +110,7 @@ to the list monad. It provides the functionality provided by `list-t` or
`logict` packages for free. Here is an example of nested looping using
the serial stream monad:

```haskell
```{.haskell}
import qualified Streamly.Prelude as S

loops = do
Expand Down Expand Up @@ -146,7 +146,7 @@ scheduling behavior. The example from the previous section can be run
with interleaved scheduling behavior as follows, without changing the
code at all:

```haskell
```{.haskell}
main = Stream.drain $ Stream.fromWserial loops
```

Expand All @@ -171,14 +171,14 @@ style. The list transformer example can be run with concurrent
execution of loop iterations as follows, without changing the code at
all:

```haskell
```{.haskell}
main = Stream.drain $ Stream.fromAhead loops
```

And interleaving with concurrent execution of the loop iterations can be
written like this:

```haskell
```{.haskell}
main = Stream.drain $ Stream.fromWAsync loops
```

Expand Down
12 changes: 6 additions & 6 deletions docs/User/HowTo/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ together to create a single transformed stream.

Distributing a value to a stream of consumers concurrently:

```haskell ghci
```{.haskell mode=ghci}
{-# LANGUAGE FlexibleContexts #-}

import Data.Function ((&))
Expand All @@ -30,7 +30,7 @@ f1 x =
Use `parApply` to zip streams concurrently. Here, we zip three singleton
streams:

```haskell ghci
```{.haskell mode=ghci}

f2 x =
let app = Stream.parApply id
Expand All @@ -43,7 +43,7 @@ f2 x =

Applying a function concurrently to your input stream:

```haskell ghci
```{.haskell mode=ghci}
g f xs =
Stream.fromList xs
& Stream.parMapM (Stream.ordered True) f
Expand All @@ -53,7 +53,7 @@ g f xs =
You can now use the concurrent map to pipe each element through multiple
transformations using the distribute/zip operations.

```haskell docspec
```{.haskell mode=docspec}
>>> g f1 [1,2,3,4::Int]
[[2,3],[3,4],[4,5],[5,6]]

Expand All @@ -65,7 +65,7 @@ Instead of using `parApply` directly, you can use `mkZipType` to
create a zip Applicative newtype so that you can use the `Applicative`
instance.

```haskell
```{.haskell}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
Expand All @@ -81,7 +81,7 @@ $(mkZippingType "ZipConcurrent" "app" True)

The `writeLastN` fold can be used to create a stream of sliding windows.

```haskell docspec
```{.haskell mode=docspec}
>>> import qualified Streamly.Data.Array as Array
>>> :{
Stream.fromList [1,2,3,4,5::Int]
Expand Down
Loading