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

Regression: 0.18 code with mapIt() fails to compile on 0.19 #9093

Closed
niv opened this issue Sep 27, 2018 · 4 comments
Closed

Regression: 0.18 code with mapIt() fails to compile on 0.19 #9093

niv opened this issue Sep 27, 2018 · 4 comments

Comments

@niv
Copy link
Contributor

niv commented Sep 27, 2018

import strutils, sequtils

let inp = "a:b,c:d"

echo inp.split(",").mapIt(it.split(":"))

This used to work on 0.18 (output: @[@["a", "b"], @["c", "d"]])

0.19 fails with:

test.nim(5, 20) template/generic instantiation from here
../.choosenim/toolchains/nim-0.19.0/lib/pure/collections/sequtils.nim(690, 19) Error: type mismatch: got <seq[string]> but expected 'string = Alias'
@kaushalmodi
Copy link
Contributor

Calling all the recent authors of mapIt:

@LemonBoy
Copy link
Contributor

Not much of a regression here, for some reason iterators are preferred to procedures in type() expressions (#8901 comes to mind) and that's enough to confuse our simple-minded mapIt.

In the following snippet:

  type outType = type((
    block:
      var it{.inject.}: type(items(s));
      op))

Where op is it.split(":") the compiler picks the split iterator that returns string instead of the split procedure that returns seq[string].

@skilchen
Copy link
Contributor

I only fixed a typo in in this procedure. Personally I would never use it.
You could try:

echo inp.split(",").mapIt(seq[string], it.split(":"))

to get the previous result, or

echo inp.split(",").mapIt(string, it.split(":"))

to get some kind of flatmap...

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Sep 28, 2018

@skilchen what is the mapIt(type, arg) syntax?

Update: Answering to myself: https://nim-lang.org/docs/sequtils.html#mapIt.t,untyped,untyped,untyped. Though, this has been deprecated for a while now.


About "flatmap", that's just a string representation of the sea, right? (Would be a pain to parse that I think).

This worked when I tried:

echo inp.split(",").mapIt($it.split(":"))

But the output of that won't be very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants