Comments (5)
We have prependK
and appendK
on Alternative
with those signatures. Sergey has optimized their implementations for standard collections in #4052 and #4055. Does that address your usecase? Thanks!
cats/core/src/main/scala/cats/NonEmptyAlternative.scala
Lines 26 to 46 in ba48b63
from cats.
Oh that's nice, didn't notice, thanks to @satorg 🙏
That seems to address my wish list above, and the intent of #1360 ✅
While on this topic, what about the co-operations to pull items out of containers, perhaps called "uncons" and "unsnoc", F[A] => (F[A], A)
?
I see we have an implementation for Chain
, but no abstraction for it afaict.
from cats.
While on this topic, what about the co-operations to pull items out of containers
You can use Comonad#extract
to e.g. get the head
of a NonEmptyList
. But off the top of my head I'm not aware of any operations for getting the tail
, or the (init, last)
.
from cats.
Also, perhaps as a work-around, there's Foldable#toIterable
that can provide access to head
and tail
, but the latter will be just Iterable
of course, not F[_]
anymore.
from cats.
-
When I tried rewriting code written in terms of
List
toM: Alternative
, I got stuck where the lists (used as stacks) get destructured to remove the head. NaturallyFoldable#toIterable
doesn't express the efficient destructure of List/Chain -like containers. -
I do think the complimentary co- operations Uncons and Unsnoc are valuable in some contexts, but should I create a separate issue as its drifted from the title?
-
What would be the correct type-class for destructuring duals to
prependK
&appendK
?Comonad
seems too specific. Would aCoSemigroupK
define somesplitK
dual tocombineK
? AndCoNonEmptyAlternative
define aunprependK
andunappendK
(perhaps with aliasesuncons
andunsnoc
)?
from cats.
Related Issues (20)
- `Tuple1SemigroupalOps` methods have different names from other `TupleNSemigroupalOps` classes HOT 3
- Instances for Currency HOT 7
- EitherT[Option, ?, ?]] can't be used as a bifunctor HOT 5
- trait EuclidianRing should not be a Ring HOT 4
- OutOfMemoryError when IO.uncancelable is used in recursive function HOT 1
- ambiguous implicit resolution of `Show.ContravariantShow[immutable.SortedMap[K, V]]` HOT 1
- Should Monad extend Defer? HOT 11
- Support Scala Native 0.5 HOT 3
- Adding an alternative version of the method whenA with a different signature
- `Eval` thread safety HOT 4
- Optimize `distinct`/`distinctBy` implementations for non-empty collections
- [PROPOSAL] Aliases for methods `traverse_` and `sequence_` HOT 7
- Any reason `intercalate` isn't exposed directly on the `Semigroup` companion object? HOT 3
- (very breaking) change in Future instances? HOT 5
- Reveal internal but public identifiers and make them `private[cats]`
- Cats Order needs an `orElseBy` combinator HOT 8
- Loss of type safety in scala 3 under certain conditions
- Make Later covariant in its type parameter
- Ease awkward constructions when doing something before raising HOT 1
- A flaky test fired in `CokleisliSuite` on the Native Platform
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cats.