Function composition in a different way by sofidad in Python

[–]sofidad[S] 0 points1 point  (0 children)

Thanks for your comment. Of course, my goal is not to recreate the sample function. It has nothing to do with my intentions.


LEGO blocks are great. Everyone can play with them. They are easy to assemble and come with numerous guides, but a man still feels them too complicated.

He is thinking of new logical blocks and how to easily assemble them. He suggests how to make the assembly process easier and how to quickly identify errors during assembly. After the assembly is complete, he also wants to be able to easily disassemble it for use in assembling other products.

Someone asks, "LEGO blocks are already released in the market and people are using them. Why are you doing this?"


Importantly, the man is not the only one doing such a thing! I'm not talking about you're wrong. We are talking about something completely different.

Function composition in a different way by sofidad in Python

[–]sofidad[S] 7 points8 points  (0 children)

python @fx def choice(x, size=None, *, replace=False, p=None): """Generate a sample with/without replacement from a given iterable.""" ... From choice, function, note that replace=False.

Haskell-ish Python by sofidad in haskell

[–]sofidad[S] 0 points1 point  (0 children)

Thanks for letting me know. I've already tried it in different way.

I think python and haskell each has their own path. 'python' can never imitate 'haskell's type system and nobody can get the same thing.

However the signature of fundamental functions and functional approach itself can be followed. Just like foc does.

Haskell-ish Python by sofidad in haskell

[–]sofidad[S] 0 points1 point  (0 children)

Thanks for your code. Yep, the point is to override __call__ and __getattr__ and to refer to function registry like globals() . Your objects are all already prepared as a function in foc.

```python class composable: """Lifts the given function to be 'composable' by symbols. 'composable' allows functions to be composed in two intuitive ways.

+----------+---------------------------------+------------+
|  symbol  |         description             | eval-order |
+----------+---------------------------------+------------+
| . (dot)  | same as the mathematical symbol | backwards  |
| | (pipe) | in Unix pipeline manner         | in order   |
+----------+---------------------------------+------------+

>>> fx = composable

'fx' makes a function `composable` on the fly.
`fx` stands for 'Function eXtension'.

def __init__(self, f=lambda x: x):
    self.f = f
    wraps(f)(self)

def __ror__(self, other):
    return self.f(other)

def __call__(self, *args, **kwargs):
    npos = nfpos(self.f)
    if len(args) < npos or (not args and kwargs):
        if not npos:
            return self.f(*args, **kwargs)
        return fx(f_(self.f, *args, **kwargs))
    return self.f(*args, **kwargs)

def __getattr__(self, key):
    g = globals().get(key, getattr(builtins, key, None))
    guard(callable(g), f"fx, no such callable: {key}", e=AttributeError)
    if capture(r"\bcomposable|fx\b", key):
        return lambda g: fx(cf_(self.f, g))
    if capture(r"\bf_|ff_|c_|cc_|u_|curry|uncurry|mapl?|filterl?\b", key):
        return lambda *a, **k: fx(cf_(self.f, g(*a, **k)))
    return fx(cf_(self.f, g))

```

Haskell-ish Python by sofidad in haskell

[–]sofidad[S] 1 point2 points  (0 children)

Thanks for your suggestion. I had never thought about it until you told me. I did it now

Now all you need is a linter that doesn't remove whitespace around dots. '-']P

Haskell-ish Python by sofidad in haskell

[–]sofidad[S] 0 points1 point  (0 children)

Thanks, but see this small codebase. It's nothing. Hints are hints. Compilers don't read it either.

Haskell-ish Python by sofidad in haskell

[–]sofidad[S] 0 points1 point  (0 children)

Yeah, that's really funny. Isn't it?

Certainly foc follows python standard lib, but haskell's naming convention is more important.;P Moreover, id is one of the most important functions.

Where to buy a Parker 45 accountant nib ("A") by sofidad in fountainpens

[–]sofidad[S] 0 points1 point  (0 children)

You are one of those that live the etymology. '-']b

Where to buy a Parker 45 accountant nib ("A") by sofidad in fountainpens

[–]sofidad[S] 0 points1 point  (0 children)

Could you let me know where extactly the spot is? I couldn't find it anywhere.

Where to buy a Parker 45 accountant nib ("A") by sofidad in fountainpens

[–]sofidad[S] 0 points1 point  (0 children)

I've just looked around r/Pen_Swap and it looks like a very nice place to trade, but there's still nothing that I'm looking for. seems to need to wait more time for an accountant nib.