Re: [elixir-core:9846] Enum.index/2

2020-12-08 Thread José Valim
I like Bruce's option a lot and I will proceed with that. Thanks Bruce and everyone! On Wed, Dec 9, 2020 at 1:48 AM Anil Kulkarni wrote: > If there was no Enum.with_index/2 function in existence today, how would > we implement it? My personal preference is to do {index, value}, as per > José’s

Re: [elixir-core:9845] [Proposal] Add JSON structured logging backend to Logger

2020-12-08 Thread José Valim
Hi Blake, Logger already provides a custom formatter and you can replace the formatter to emit JSON instead. We don't intend to include a JSON specific formatter by default because this is something that can be trivially done as a library (and there is no benefit doing it from core itself

[elixir-core:9845] [Proposal] Add JSON structured logging backend to Logger

2020-12-08 Thread Blake Kostner
Considered the growth of structured logging, it would be really nice if elixir included a JSON Logger backend by default. This would be very basic and not include any weird paths or third party service specific fields, but it would wrap up multi line outputs (like stack traces) to a single line

Re: [elixir-core:9842] Enum.index/2

2020-12-08 Thread Adam Lancaster
You could also use the new zip_with: Map.new(Enum.zip_with(list, 0..length(list), & {&2, &1})) On Tue, 8 Dec 2020 at 23:51, Christopher Keele wrote: > I think that even if it enabled awesome optimization opportunities, > 1. Having both *Enum.index_with* and *Enum.index*/*indexed* will confuse

Re: [elixir-core:9842] Enum.index/2

2020-12-08 Thread Christopher Keele
I think that even if it enabled awesome optimization opportunities, 1. Having both *Enum.index_with* and *Enum.index*/*indexed* will confuse people. 2. Straying from Elixir's consistent API design of "Module X functions take X's as their first argument" will confuse people. a. Especially in

Re: [elixir-core:9840] Enum.index/2

2020-12-08 Thread Bruce Tate
There is a bit of a collision with the option for the offset, but you could pattern match that. -bt On Tue, Dec 8, 2020 at 4:57 PM Zach Daniel wrote: > I like that idea a lot Bruce. Let’s you do something like: > > maps |> Enum.with_index((&1, :index, &2)) > > On Tue, Dec 8, 2020 at 4:50 PM

Re: [elixir-core:9839] Enum.index/2

2020-12-08 Thread Zach Daniel
I like that idea a lot Bruce. Let’s you do something like: maps |> Enum.with_index((&1, :index, &2)) On Tue, Dec 8, 2020 at 4:50 PM Bruce Tate wrote: > Maybe a transform function on with_index? > > Enum.with_index([:a, :b, :c], &{&2, &1}) > > -bt > > On Tue, Dec 8, 2020 at 3:05 PM José Valim

Re: [elixir-core:9838] Enum.index/2

2020-12-08 Thread Bruce Tate
Maybe a transform function on with_index? Enum.with_index([:a, :b, :c], &{&2, &1}) -bt On Tue, Dec 8, 2020 at 3:05 PM José Valim wrote: > I would like to propose an Enum.index/2 function. It behaves like > with_index/2 but the index is the first argument: > > iex> Enum.index([:a, :b, :c])

Re: [elixir-core:9837] Enum.index/2

2020-12-08 Thread Paul Clegg
FWIW, I like the "indexed" function name; I think the past tense of the verb helps indicate what it returns. The ambiguous nature of the verb/noun "index" in English makes for confusion, for sure. "What does Enum.indexed do?" "It returns the Enum, indexed." "Ah." ...Paul On Tue, Dec 8,

Re: [elixir-core:9836] Enum.index/2

2020-12-08 Thread Zach Daniel
I commonly need to flip the keys/values when using Map.new, why not add an option to Map.new? I don’t like this name, but this reads pretty nicely to me list |> Enum.with_index() |> Map.new(flip: true) On Tue, Dec 8, 2020 at 4:35 PM Austin Ziegler wrote: > I’m not opposed to the idea, but

Re: [elixir-core:9835] Enum.index/2

2020-12-08 Thread Austin Ziegler
I’m not opposed to the idea, but wouldn’t that map be easily done with: Map.new(Enum.with_index(data), fn {v, k} -> {k, v} end) The biggest advantage of Map.new(Enum.index(data)) is that the number of tuple creations is halved. -a On Tue, Dec 8, 2020 at 4:10 PM José Valim wrote: > The

Re: [elixir-core:9834] Enum.index/2

2020-12-08 Thread José Valim
The main reason for an index function is to make it easier to build a map: Map.new Enum.index(data) I agree the duplicity between noun and verb is undesirable though. On Tue, Dec 8, 2020 at 9:52 PM Kelvin Raffael Stinghen < kelvin.sting...@gmail.com> wrote: > I can't see why not just `x |>

Re: [elixir-core:9834] Enum.index/2

2020-12-08 Thread Kelvin Raffael Stinghen
I can't see why not just `x |> Stream.with_index() |> Stream.map(fn {v, i} -> {i, v} end)`... I mean, lots of proposals for similar functions got denied because it would be easy to develop a lib that does it cause Elixir is awesomely extensible, so why bothering add another variant? Do you have

Re: [elixir-core:9832] Enum.index/2

2020-12-08 Thread Greg Vaughn
If this is related to the mystery benchmark tweets, José, then I guess I'm in favor of the proposal :-) I do prefer Felipe's name of `Enum.indexed/1` though. While `index` can be a verb, it's ambiguous with the noun. `indexed` is clearly a past tense verb. -Greg Vaughn > On Dec 8, 2020, at

Re: [elixir-core:9831] Enum.index/2

2020-12-08 Thread Andrew Fontaine
I'm not sure I see the benefit of the new Enum.index/2 over Enum.with_index/2 and Enum.map/2. That is to say, why would the language need both? I will admit it makes piping into Enum.into/2 potentially nicer. -- You received this message because you are subscribed to the Google Groups

Re: [elixir-core:9830] Enum.index/2

2020-12-08 Thread Felipe Stival
That's a really good point. Maybe `indexed`? `with_index` sounds like perfect past for me, so this would be similar. Still `index` is fine. About the function itself, I find it useful and believe it should be on Enum. Em ter., 8 de dez. de 2020 às 17:14, José Valim escreveu: > I considered the

Re: [elixir-core:9829] Enum.index/2

2020-12-08 Thread José Valim
I considered the option but I prefer to avoid using options that change the return type. On Tue, Dec 8, 2020 at 9:11 PM Felipe Stival wrote: > I'm not sure. Sounds a bit ambiguous, couldn't this be an option for a new > Enum.with_index/3? > > Em ter., 8 de dez. de 2020 às 17:05, José Valim >

Re: [elixir-core:9828] Enum.index/2

2020-12-08 Thread Felipe Stival
I'm not sure. Sounds a bit ambiguous, couldn't this be an option for a new Enum.with_index/3? Em ter., 8 de dez. de 2020 às 17:05, José Valim escreveu: > I would like to propose an Enum.index/2 function. It behaves like > with_index/2 but the index is the first argument: > > iex>

[elixir-core:9827] Enum.index/2

2020-12-08 Thread José Valim
I would like to propose an Enum.index/2 function. It behaves like with_index/2 but the index is the first argument: iex> Enum.index([:a, :b, :c]) [{0, :a}, {1, :b}, {2, :c}] I am hoping it reads "index" this tuple (hence the index as the first element. While with_index means attach an

[elixir-core:9827] [Proposal] Autoformat examples in doctests

2020-12-08 Thread Artur Plysyuk
It is not very easy to write multiline in doctests manually. It would be great if autoformatter is applied to doctests too. -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it,