# Map-function with range syntax map(f❌kw, seq)

**URL:** <https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354>\
**Category:** General Usage\
**Created:** [March 8, 2024, 12:45pm UTC](https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354 "2024-03-08T12:45:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard-hartmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/richard-hartmann/32/202548_2.png) [@richard-hartmann](https://discourse.julialang.org/u/richard-hartmann)\
**Post date:** [March 8, 2024, 12:45pm UTC](https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354/1 "2024-03-08T12:45:57Z")

</div>

Hey,  
I came across the following syntax.

```julia
map(f:x:kw, ys)

```

I would be very happy if someone could explain that line in detail to me. Or hint me to the appropriate page of the julia documentation. So far I was not able to find anything useful.

A minimal example for using that line might look like

```julia
function f(x, y; info=false)
    @info "inside f" x y info
    return 42
end

x = 2
ys = [4,5,6]
kw = (;info=true)
map(f:x:kw, ys) 

```

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 8, 2024, 1:03pm UTC](https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354/2 "2024-03-08T13:03:05Z")

</div>

> [@richard-hartmann](#):
>
> I came across the following syntax.

where?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 8, 2024, 1:03pm UTC](https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354/3 "2024-03-08T13:03:11Z")

</div>

This is invalid syntax, and results in

```julia
julia> map(f:x:kw, ys)
ERROR: MethodError: no method matching (::Colon)(::typeof(f), ::Int64, ::@NamedTuple{info::Bool})

```

There must be a typo somewhere.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [March 8, 2024, 1:04pm UTC](https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354/4 "2024-03-08T13:04:01Z")

</div>

While it is correct syntax, your example does not run. It is very hard to tell what it should do.

Would it be possible, that the first colon should have been a comma? Like e.g.

```julia-repl
julia> f(x,y) = @info "" x y
f (generic function with 1 method)

julia> x = 2; y=5; ys=[7,8,9];

julia> map(f, x:y, ys)
┌ Info: 
│ x = 2
└ y = 7
┌ Info: 
│ x = 3
└ y = 8
┌ Info: 
│ x = 4
└ y = 9
3-element Vector{Nothing}:
 nothing
 nothing
 nothing

```

The `a:b:c` constructs a range and just means `range(;start=a, stop=c, step=c)`.

---

<div class="post-metadata">

**Author:** ![richard-hartmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/richard-hartmann/32/202548_2.png) [@richard-hartmann](https://discourse.julialang.org/u/richard-hartmann)\
**Post date:** [March 8, 2024, 1:13pm UTC](https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354/5 "2024-03-08T13:13:21Z")

</div>

You are right, while boiling things down to a minimal example, I forgot to include.

```julia
using StdLib

```

As I found out, here the colon operator is defined for callables, allowing for a condensed way to construct Fixes. So

```julia
f:x:kw 

```

becomes a callable with only one parameter (effectively `y`), thus suited for the map function.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 8, 2024, 1:25pm UTC](https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354/6 "2024-03-08T13:25:21Z")

</div>

> [@richard-hartmann](#):
>
> `using StdLib`

what is this? can you point us to where are you getting these examples/tutorials？

---

<div class="post-metadata">

**Author:** ![richard-hartmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/richard-hartmann/32/202548_2.png) [@richard-hartmann](https://discourse.julialang.org/u/richard-hartmann)\
**Post date:** [March 8, 2024, 1:30pm UTC](https://discourse.julialang.org/t/map-function-with-range-syntax-map-fkw-seq/111354/7 "2024-03-08T13:30:48Z")

</div>

At least to me, it is now all clear. But thanks anyway.
