--target 3
(or above) and also supports a host of unicode alternatives to built-in operators.
typeclasses
or something, though addpattern
is probably going to be better than any library like that if you're working in Coconut.
toolz
's valmap
function?
addpattern fmap(f, obj is MyClass) = obj.map(f)
fmap
be a pattern matched function so that this functionality could be added to third party libraries
fmap
withmatch def my_fmap(obj is ThirdPartyObject, func) = ...
addpattern def my_fmap(obj, func) = fmap(obj, func)
Hey all, I'm really new to coconut, and I think this is the right place for this question, but if I'm wrong, let me know.
Is there anyway in coconut to pipe an object and then call a method of that object, passing one of that objects' attributes as an argument of the method?
This question really arises from using pipes with pandas where I want to use a pipe to process a dataframe, and in that pipe change the index of that dataframe and then later access this new index as an argument within a .groupby() call or something similar. Of course I could assign a new dataframe variable, and complete this task but I was hoping there was a way to avoid it.
Here is a simple (and useless) example of what I'd like to do:
class A_Class:
attribute = 1
def method (self, argument):
print(f"The argument is {argument}")
an_object = A_Class()
an_object |> \
.method(.attribute)
Output: The argument is operator.attrgetter('attribute')
My Desired Output: The argument is 1
Is there anyway to do what I'm trying to do? Am I misunderstanding something crucial? Thank you!
Hi! I was looking for a VI-Mode for the Coconut REPL. I couldn't find any such configuration option in the documentation or the FAQ. I took a look at the source and there is prompt_vi_mode
in constants.py
and it is initially set to false. How do I set it to true? (without changing the source obviously)
Also, I find it weird that Coconut doesn't use GNU Readline like the Python REPL. Just out of curiosity, is there any specific reason for that?
We could for sure use a lot of the Python language server, however, on top of what you said, I also see an issue with code completion/type inferencing when using the superset.
As for the implementation of disc. unions, that'd be a little clunky. Trying to think of something that'd run in all versions, we'd compile a class with an array of the field names and then when we match, we'd essentially just be matching on values in that array for which we can return self.field. I'm pretty sure type inferencing on that would be out the window, though.
It might.
I usually use discriminated unions to wrap possible function arguments. Below is what I was hoping for.
possible_args = ( option1: str, option2: int, option3: MyCustomDeeplyNestedObject )
def my_function( args : possible_args ) :
match args:
case str instance_variable: exprs / stmnts on strings
case int instance_variable: exprs / stmnts on ints
case MyCustomDeeplyNestedObject instance_variable: exprs / stmnts on MyCustomDeeplyNestedObject
But I'm not sure if I can use is
in that match statement. That would be checking to make sure the variable refers to the same object reference, right?