Simple, elegant, Pythonic functional programming.
APACHE-2.0 License
Bot releases are hidden (Show)
See Coconut's documentation for more information on all of the features listed below.
Language features:
match def f(x, y=x) = (x, y)
.[. ; a]
).(x := .)
implicit partial syntax (only available in pipes).lift_apart
built-in combinator.(if)
operator function.fmap
support for bytes
and bytearray
.xarray
to match existing numpy
/pandas
support.to
argument to all_equal
.Compiler features:
coconut-run
and coconut --run
now work on packages rather than just files.Bugfixes:
Published by evhub 11 months ago
This is primarily a bugfix release to resolve #804. See Coconut's documentation for more information on all of the features listed below.
Language changes:
where
statements now use temporary variable names to limit the scope of contained assignments.async_map
function utilizing anyio
to work with asyncio
or trio
.mapreduce
, collectby.using_threads
, collectby.using_processes
, mapreduce.using_threads
, and mapreduce.using_processes
built-ins..method[index]
implicit partials.--strict
is passed). Specifically:
recursive_iterator
-> recursive_generator
parallel_map
-> process_map
concurrent_map
-> thread_map
__name__
attribute.ExceptionGroup
using the exceptiongroup
module.Compiler changes:
api.find_packages
and api.find_and_compile_packages
utilities for working with Coconut packages.--fail-fast
option to fail upon the first error when compiling multiple files.--history-file
command-line option has been removed; use COCONUT_HISTORY_FILE
environment variable if you really need it.Bugfixes:
cPyparsing
versions.override
now works in conjunction with classmethod
and staticmethod
.Published by evhub about 1 year ago
See Coconut's documentation for more information on all of the features listed below.
New features:
and_then
and and_then_await
built-ins for async function composition.Language changes:
x => x
) as an alternative to skinny arrows (x -> x
) to better distinguish them from type annotations. Skinny arrow lambdas will be deprecated at some later date.f
-string syntax on all targets.f
-strings with no expressions in them (e.g. f"why does this have an f"
will now show a warning by default and an error on --strict
.Compiler changes:
--line-numbers
are now on by default. Pass --no-line-numbers
to turn them off.coconut-run
.--target psf
support for targeting all versions not considered end-of-life.coconut --jupyter install
command for easily installing all Jupyter kernels added as an alternative to the existing coconut --jupyter
syntax.Bugfixes:
multiset
methods should now always return multiset
s when the arguments are all multiset
s rather than Counter
s.xonsh
.MYPYPATH
to include the entire directory that Coconut has been installed into when running with --mypy
.Published by evhub over 1 year ago
See Coconut's documentation for more information on all of the features listed below.
This is another patch release, mainly for #751 and #755.
New features:
async with for
loops provide a simple syntax for implementing the recommended pattern for handling async
generators.Language changes:
typing
imports will redirect to typing_extensions
whenever possible to ensure you always get the latest implementation of typing
objects on all versions.async
generators and some related utilities will now be automatically backported to 3.5 via the async_generator
library.Compiler changes:
coconut.convenience
renamed to coconut.api
(coconut.convenience
is still available as an alias for backwards compatibility).Bugfixes:
xonsh
will no longer throw an error in certain situations.Published by evhub over 1 year ago
See Coconut's documentation for more information on all of the features listed below.
This is a patch release primarily aimed at fixing #746, though it also brings a couple of new features and other fixes as well.
New features:
f(...=long_name)
syntax as a shorthand for f(long_name=long_name)
.f ..> g
will now preserve the signature of f
when inspected using inspect.signature
.Language changes:
fmap
will now raise TypeError
rather than falling back to a default implementation when it encounters an unknown type. For backwards compatibility, the old behavior can be recovered with fmap$(fallback_to_init=True)
.fmap
now works properly on multiset
.Bugfixes:
xonsh
will no longer fail on semicolon-seperated commands when using the Coconut extension.--stand-alone
mode will now properly make use of --jobs
.Published by evhub over 1 year ago
Coconut v3! See Coconut's documentation for more information on all of the features listed below.
Note that v3 is a major version release that comes with some breaking changes, though Coconut will do its best to warn you if your code does anything that changed from v2 to v3.
Breaking changes:
set
patterns now work like dict
patterns where they allow extra keys, such that {1, 2}
will match {1, 2, 3}
. To get back the strict behavior, use the {1, 2, 3, *()}
pattern. Coconut will warn you if your code contains set patterns without an explicit strictness marker.f x**2
is now equivalent to f(x**2)
rather than f(x)**2
. Coconut will warn you if your code contains expressions with new precedence..$[]
will now only default to using an existing __getitem__
if the object is registered as a collections.abc.Sequence
. __iter_getitem__
will still always be used. Lets you do things like {"k": "v"}$[0]
.obj.
syntax as a shorthand for getattr$(obj)
deprecated.--jobs
now defaults to sys
rather than 0
.New features:
a x**2 + b x + c
, with support for single variable names and numeric constants as coefficients.copyclosure def
functions that copy their closures on function creation, allowing them to e.g. hold on to loop variables.(+)
syntax in a typing context now yields a typing.Protocol
that requires supporting that operator.&:
operator for combining multiple typing.Protocol
's into a single protocol.addpattern def
even if there's no existing function of that name, allowing you to use addpattern def
for every pattern rather than having to use match def
for the first one.x |> await
syntax for using await
in pipes.pandas
support.frozenset
and multiset
patterns.Bugfixes:
(in)
operator function argument ordering.is not
and not in
operator functions now supported.xonsh
loading and fixed xontrib unload coconut
.xonsh
commands when using Coconut's xonsh
plugin.dict
now always functions as on the latest Python 3 on any Python version.super
compatibility across Python versions and some cases where super()
wouldn't work.coconut --jupyter qtconsole
.Published by evhub almost 2 years ago
See Coconut's documentation for more information on all of the features listed below.
Major changes:
multiset
built-in based on collections.Counter
, including new multiset literal syntax (m{1, 1, 2, 3, 3, 4}
).Expected
built-in based on Haskell's Either
, plus new safe_call
built-in that calls a function while collecting any errors into an Expected
. Additionally, the of
built-in has been renamed to call
(of
is still available as a deprecated alias when compiled without --strict
).windowsof
built-in for iterating over sliding windows of the given iterable.cartesian_product
built-in as an enhanced version of itertools.product
including numpy
support.cycle
built-in as an enhanced version of itertools.cycle
.map
now supports a strict=True
keyword-only argument that works as in zip
.flatten
now supports a levels
argument for how many levels to flatten.groupsof
now supports a fillvalue
argument to pad the last group.addpattern
now accepts any number of pattern-matching functions.memoize
now accepts a function to memoize as the first argument.None
-aware function composition pipes (e.g. f ..?> g
).Minor changes:
<:
syntax instead of :
or <=
(e.g. def f[T <: int[])(xs: T) -> T = ...
).None
-aware pipes now supported (e.g. <?|
).data
types with default arguments now allows those defaults to be elided in the match
.::
now produces a reiterable object when called on reiterable objects.MatchError
s when compiled in --package
mode.__bool__
magic method fixed on Python 2.--no-wrap
.--strict
.fmap
has been improved.numpy
support for some built-ins.weakref
able.Published by evhub almost 2 years ago
v2.1.1 is a relatively small release on top of v2.1.0 primarily releasing now to provide Python 3.11 support, though v2.1.1 also has a couple of exciting new features, primarily Coconut's new type parameter syntax. See Coconut's documentation for more information on all of the features listed below.
Bugfixes:
Major changes:
def ident[T](x: T) -> T = x
.Minor changes:
mypy
type checkers should now have an easier time type-checking Coconut code.async (...) -> ...
and (..., **P) -> ...
enhanced type annotation constructs for Callables following PEP 677.f = async def x -> x
async statement lambda syntax now supported.x |> (.+1)
syntax now produces better optimized compiled Python.case
/match
syntax now deprecated on --strict
in favor of Python 3.10 match
/case
syntax.Published by evhub almost 2 years ago
Though a small release relative to v2.0.0, v2.1.0 includes a couple of pretty exciting changes, most notably custom operators and substantial performance improvements. See Coconut's documentation for more information on all of the features listed below.
Major changes:
xonsh
, etc.). Compile times for large files should be unchanged.multi_enumerate
built-in for enumerating multi-dimensional arrays (e.g. numpy
arrays).Minor changes:
mypy
errors.xonsh
support updated to the latest xonsh
version, should now be enabled by default without requiring xonsh install coconut
, and should now be substantially faster.in <expr>
pattern for easier containment checking in pattern-matching.NOQA
/noqa
comments when showing warnings for unused imports in --strict
mode.Published by evhub about 2 years ago
Coconut v2 is here! This is Coconut's first ever major version release since Coconut was first published, and it comes with some breaking changes, detailed below. Care has been taken to keep v2 as backwards-compatible as possible, but Python 3.10 adding pattern-matching of its own that conflicted with some of Coconut's old pattern-matching rules meant that breaking changes were going to be inevitable to ensure full compatibility.
Additionally, v2 introduces some pretty major new features such as multidimensional array literal/concatenation syntax! Check it all out below and see Coconut's documentation for more information on all of the features listed.
Breaking changes:
x is int
type-checking syntax is now deprecated in favor of using the int(x)
class pattern. For cases where there is no rewriting as a class pattern, x `isinstance` int
syntax is also supported.{"a": a}
now matches a dictionary with at least "a"
as a key rather than exactly "a"
as its only key to be consistent with Python 3.10. Coconut will warn if such syntax is detected and suggest the explicit {"a": a, **_}
or {"a": a, **{}}
syntax instead.data
types no longer support adding or multiplying them like tuples unless explicitly added via __add__
/__mul__
methods.fmap
over a Mapping (e.g. dict
) now does a normal map instead of a starmap
. Thus, you'll need to do fmap$(def ((k, v)) -> (new_k, new_v))
instead of fmap$((k, v) -> (new_k, new_v))
. Old behavior can also be recovered with fmap$(starmap_over_mappings=True)
.($[])
spelling for the iterator slicing operator function has been removed in favor of .$[]
and the normal getitem operator has been added as .[]
...
has been lowered such that f x .. g y
is now equivalent to (f x) .. (g y)
rather than ((f x) .. g) y
.initializer
keyword argument in scan
changed to initial
to match the function signature of reduce
.New language features:
[a ; a]
, write out 2D array literals as [1, 2;; 3, 4]
, with the number of semicolons denoting the axis from the end on which to concatenate.(.+1)
, (a+.)
, (.<|x)
, including support for custom operators as (. `plus` x)
.x: typing.Tuple[int, str]
, just: x: (int; str)
.(a=1, b=2)
.func$(kwd_arg=?)
.lift
to "lift" a function up so that its arguments become unary functions. Also: ident, flip, const, of.all_equal
and collectby
built-ins for working with iterables.fmap
now supports asynchronous iterators.=<expr>
has been deprecated in favor of ==<expr>
; the former syntax will now raise an error in --strict
mode..attr=<match>
syntax that raises an error if the attr
isn't present rather than failing the match.[1] + x + [2] + y + [3]
).as x
(to explicitly bind a variable) and is x
(to do an identity check) pattern-matching constructs.a `pred` or b = <expr>
syntax that binds to a
if pred
and b
otherwise.jax
support in fmap
and multidimensional array literal/concatenation.(,)
for joining arguments into a tuple and new (raise)
operator function for raising an exception.@
now supported on all Python versions.super()
now supported on all Python versions.typing
imports into typing_extensions
imports when necessary.:=
assignment expressions can now be chained without parentheses.New compiler features:
xontrib
in the xonsh
shell to enable Coconut syntax.papermill
.coconut[kernel]
installation option for installing only lightweight Jupyter kernel dependencies compared to the full support offered by coconut[jupyter]
.coconut.convenience
API.Bugfixes:
coconut --watch
for watching files for changes to be recompiled fixed.numpy
arrays by registering them as Sequences.Published by evhub almost 3 years ago
Barring any necessary hotfixes, this release, v1.6.0
, will be the last release on the v1.X.X
branch—which means next up is Coconut v2
! Coconut v2
will include substantial backwards-incompatible changes to Coconut's pattern-matching syntax, as well as likely including other backwards-incompatible changes as well.
Coconut v1.6.0
includes a substantial list of new features, many of which have been added in anticipation of Coconut v2
. See Coconut's documentation for more information on all of the features and bugfixes listed below.
New language features:
3.9
, Python 3.10
, and/or Python 3.11
.@override
built-in that, when used to decorate a method, asserts that it is overwriting some method from a base class.flatten
built-in for flattening one layer of an iterable of iterables.reveal_type
and reveal_locals
built-ins that will print the inferred type of the contained expression when compiled with coconut --mypy
.yield def
function definition syntax for explicitly specifying that you want a generator function, regardless of whether a yield
actually occurs somewhere in the function.if condition then x else y
ternary syntax in addition to Python's x if condition else y
ternary syntax..[0][1]
and .a.b(c)
implicit partials.dict
, tuple
, and list
star and double-star unpackings across all Python versions.int | bool
type annotation syntax, including compiling it to any Python version.zip
and zip_longest
built-ins now supports a Python-3.10-style strict
keyword argument on all Python versions.class A(metaclass=...)
syntax on all Python versions, including compiling to universal code to support Python 2.exec
as a function on all Python versions.enum
imports into aenum
imports on targets that don't support enum
.==
instead of =
as the prefix for equality checking in pattern-matching (this will be made mandatory in Coconut v2
).case
syntax now allows a cases
keyword to be used at the top level instead of the case
keyword for clarity.as x
explicit name-binding syntax in pattern-matching.New compiler features:
--and src dest
flag for compiling additional files/directories with the same coconut
command, including splitting the compilation across multiple processes when --jobs
is passed.# coding: coconut
header in .py
files to use Coconut syntax along with a coconut --site-install
command to make all such automatic compilation behavior available without first importing coconut.convenience
.--vi-mode
flag and COCONUT_VI_MODE
environment variable for enabling vi
mode in the interpreter.coconut[backports]
rather than individually as in installing coconut[asyncio]
.Bugfixes:
dataclasses
library exists at runtime, all Coconut targets now support x: int
syntax for specifying the fields of a dataclass
.parallel_map
is now substantially more efficient in processing very large iterators.or
and |
in pattern-matching will no longer sometimes run duplicate checks.--no-wrap
now disables from __future__ import annotations
on Python 3.7+.with
statements.f
-strings placed next to each other.:=
operators inside of ::
expressions to invalid Python.Coconut v1.6.0
should also compile about 10% faster on average than Coconut v1.5.0
.
Published by evhub over 3 years ago
See Coconut's documentation for more information on everything listed below.
Features
from coconut import embed; embed()
.None
-aware pipe operators.zip_longest
built-in.=
specifier in f
-strings..multiple_sequential_calls()
context managers to parallel_map
and concurrent_map
.nb_conda_kernel
support (thanks @tbsexton for reporting the issue).--no-wrap
flag (thanks @QuestofIranon for the PR!).Bugfixes:
coconut --jupyter
calling the wrong Jupyter installation (thanks @betabrain for reporting the issue).setuptools
versions (thanks @fabianhjr for the PR!).f
-string parsing (thanks @bjo for reporting the issue).return
s on all Python versions.Published by evhub almost 5 years ago
See Coconut's documentation for more information on everything listed below.
Bugfixes:
=
function definition returning string literals not working (thanks @vietspaceanh for the issue!)f b.x c.y
)Published by evhub almost 5 years ago
See Coconut's documentation for more information on all of the features listed below.
Bugfixes:
cPyparsing
by defaulttrollius
on Python 3 when doing pip install coconut[all]
(thanks @DennisMitchell for the issue!)New features:
addpattern
now issues a warning if passed a non-pattern-matching function unless allow_any_func=True
is passed (thanks @m-burst for the PR and @pavelbraginskiy for the issue!)f x y
is now supportedPublished by evhub about 5 years ago
See Coconut's documentation for more information on all of the features listed below.
New features:
addpattern def
shorthand syntax (thanks @MichalMarsalek for the issue!)|**>
kwargs pipes (thanks @ArneBachmann for the issue!)(assert)
operator function (thanks @arnauorriols for the issue!)fmap
now works on numpy arrays (thanks @hoishing for the issue!)data
definitions (thanks @arnauorriols for the issue!)--target 3.8
(thanks @terrdavis for the issue!)data
types are now hashable (thanks @m-burst for the PR!)addpattern
, recursive_iterator
, and TCO'd functions are now pickleable__coconut__.py
files are created when compiling in --package
modePlus lots and lots of bugfixes!
Published by evhub about 6 years ago
See Coconut's documentation for more information on all of the features listed below.
New features:
where
clausesmemoize
decorator (thanks @iamrecursion!)TYPE_CHECKING
constantM `bind` x -> y
syntaxdata
type equality is now typed (thanks everyone in #418!)match ... not in ...
count
now supports a step size of 0
scan
now has an initializer argument--strict
now warns on unused importsreload
built-in (thanks, @ArneBachmann!)f..g(x)
is the same as f..(g(x))
not (f..g)(x)
Plus lots and lots of bugfixes!
Published by evhub almost 7 years ago
This is a bugfix release for v1.3.0
. See v1.3.0
below for all the most recently added features.
Fixes:
--watch
placing compiled files in the wrong location (thanks, @dileep-kishore!)--jupyter console
on Windows (thanks, @mlarocca!)Published by evhub about 7 years ago
See Coconut's documentation for more information on all of the features listed below.
New features:
data
types now support default argumentsdata
types now support type annotations (thanks, @jonathanplatzer!)starmap
built-inreiterable
built-in (thanks, @pchampin!)scan
built-ingroupsof
built-in (thanks, @kbaskett248!)datamaker
deprecated in favor of new makedata
built-inprepattern
deprecatedfmap
of a mapping now iterates over its .items()
--argv
command-line optionconda
cPyparsing
for faster parsingFixes:
__doc__
type: ignore
comments now work properlyrecursive_iterator
error (thanks, @pchampin!)StringIO
and BytesIO
on Python 2 (thanks, @cgarciae!)pyparsing
versionsPublished by evhub over 7 years ago
See Coconut's documentation for more information on all of the features listed below.
New features:
fmap
built-in that preserves data types (thanks, @hasufell!)data name(*args)
syntax now supporteddata from
syntax for data type inheritance--no-tco
option to disable tail call optimization (also implied by --mypy
).method(**kwargs)
implicit partial now supported.[a:b, c:d]
implicit partial now supported (thanks, @cgarciae!)Fixes:
--watch
flag resolved (thanks, @Nexus6!)conda
installation bug fixed (thanks, @bmcguirk!)Published by evhub over 7 years ago
See the previous release, v1.2.1, for information on recently released features. v1.2.2 is simply a bugfix release for v1.2.1.
Fixes: