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 fmap built-in #237

Closed
evhub opened this issue Mar 15, 2017 · 11 comments
Closed

Add fmap built-in #237

evhub opened this issue Mar 15, 2017 · 11 comments

Comments

@evhub
Copy link
Owner

evhub commented Mar 15, 2017

fmap would look like:

def fmap(func, obj) =
    obj |> map$(func) |*> obj.__class__
@evhub evhub added the feature label Mar 15, 2017
@evhub evhub added this to the v1.2.3 milestone Mar 15, 2017
@Sitwon
Copy link

Sitwon commented Mar 15, 2017

Is the intention here a variation on map that returns an iterable of the same kind?
Eg, list -> list, tuple -> tuple, str -> str?

@evhub
Copy link
Owner Author

evhub commented Mar 15, 2017

@Sitwon Yep, that's exactly it! There was a discussion on Gitter that this stems from about adding more FP-style tools to Coconut. The rationale is that if you added a function like the above, it would make it a lot easier to do this:

>>> data Nothing()
>>> data Just(n)
>>> Just(3) |> map$(-> _*2) |*> Just
Just(n=6)
>>> Nothing() |> map$(-> _*2) |*> Nothing
Nothing()

@evhub
Copy link
Owner Author

evhub commented Mar 16, 2017

An interesting question--should there also be a parallel_fmap and a concurrent_fmap in addition to just fmap? I can't see an obvious use case, but it's possible one exists.

evhub added a commit that referenced this issue Mar 16, 2017
@evhub evhub changed the title Add fmap built-in (and potentially other FP staple functions) Add fmap built-in Mar 16, 2017
evhub added a commit that referenced this issue Mar 16, 2017
@hasufell
Copy link

This doesn't work on lists as expected though:

[1,2,3] |> fmap$(_ -> _ + 1)

yields

TypeError: list() takes at most 1 argument (3 given)

@evhub
Copy link
Owner Author

evhub commented Mar 16, 2017

@hasufell Agreed. I just finished a much more complicated version that should do the trick, however. I've put it up on coconut-develop, so if you want to test it out just pip install coconut-develop and you should be able to play around with the new fmap function there.

@evhub evhub added the resolved label Mar 16, 2017
@evhub evhub closed this as completed Mar 16, 2017
@evhub
Copy link
Owner Author

evhub commented Mar 16, 2017

@hasufell @Sitwon This is now ready to be released on the v1.2.3 milestone. You can check it out now on coconut-develop with pip install coconut-develop (like I said above).

@hasufell
Copy link

On develop branch I get the following error for python-2.7:

Compiling /var/tmp/paludis/build/dev-lang-coconut-scm/image//usr/x86_64-pc-linux-gnu/lib/python2.7/site-packages/coconut/command/mypy.py ...
SyntaxError: 'return' with argument inside generator (mypy.py, line 44)

@evhub
Copy link
Owner Author

evhub commented Mar 17, 2017

@hasufell I have no idea how you managed to trigger that error--why are you trying to compile mypy.py?

@hasufell
Copy link

why are you trying to compile

Because that's what my package manager does when I install coconut.

@evhub
Copy link
Owner Author

evhub commented Mar 17, 2017

@hasufell Huh. What package manager are you using? Are you not installing Coconut through pip?

Regardless, I changed the code around a bit and that file should compile fine on 2.7 now, though it still should never be run except on Python 3. Try it now!

@hasufell
Copy link

hasufell commented Mar 17, 2017

Huh. What package manager are you using? Are you not installing Coconut through pip?

No, I'm using paludis under exherbo. I've packaged coconut manually.

Try it now!

Yes, works now!

@evhub evhub mentioned this issue May 12, 2017
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

3 participants