Skip to content

Commit 109f79b

Browse files
committed
Add do-block syntax example to readme
1 parent 7ee53cd commit 109f79b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ julia> uprint(pac, :block)
5757
▀▀██████▀▀
5858
```
5959

60-
It is also possible to pass a filtering function, filling values for which the function returns `true`, e.g. all even numbers in the following array:
60+
When passing a filtering function,
61+
UnicodeGraphics will fill all values for which the function returns `true`,
62+
e.g. all even numbers using `iseven`:
6163
```julia
6264
julia> ghost = [
6365
1 7 7 7 7 8 6 4 6 3 9 9 9 7
@@ -73,7 +75,7 @@ julia> ghost = [
7375
4 2 6 4 2 6 8 6 6 2 8 8 8 8
7476
8 2 3 6 6 8 9 1 2 4 8 5 4 8
7577
8 3 7 3 8 6 9 3 6 6 1 9 1 6
76-
];
78+
]; # a ghost is hidden in here
7779

7880
julia> uprint(iseven, ghost)
7981
⢀⠴⣾⣿⠷⣦⡀
@@ -82,9 +84,8 @@ julia> uprint(iseven, ghost)
8284
⠁⠀⠉⠀⠉⠀⠈
8385
```
8486

85-
Non-number type inputs are also supported,
87+
Non-number type inputs are supported,
8688
as long as the filtering function returns boolean values:
87-
8889
```julia
8990
julia> A = rand("abc123", 4, 4)
9091
4×4 Matrix{Char}:
@@ -98,6 +99,28 @@ julia> uprint(isletter, A, :block)
9899
▄▄ █
99100
```
100101

102+
Instead of passing a function directly,
103+
[do-block syntax](https://docs.julialang.org/en/v1/manual/functions/#Do-Block-Syntax-for-Function-Arguments) can be used:
104+
```julia
105+
julia> A = [x + y * im for y in 10:-1:1, x in 1:10]
106+
10×10 Matrix{Complex{Int64}}:
107+
1+10im 2+10im 3+10im 8+10im 9+10im 10+10im
108+
1+9im 2+9im 3+9im 8+9im 9+9im 10+9im
109+
1+8im 2+8im 3+8im 8+8im 9+8im 10+8im
110+
111+
1+3im 2+3im 3+3im 8+3im 9+3im 10+3im
112+
1+2im 2+2im 3+2im 8+2im 9+2im 10+2im
113+
1+1im 2+1im 3+1im 8+1im 9+1im 10+1im
114+
115+
julia> uprint(A) do x
116+
φ = angle(x)
117+
φ < π/4
118+
end
119+
⠀⠀⠀⢀⣴
120+
⠀⢀⣴⣿⣿
121+
⠐⠛⠛⠛⠛
122+
```
123+
101124
Multidimensional arrays are also supported:
102125
```julia
103126
julia> A = rand(Bool, 4, 4, 1, 2)

0 commit comments

Comments
 (0)