NonEmptySeq
See original GitHub issueGiven that we’re going to add some NonEmpty collections, it will be natural to wish we had a NonEmptySeq that could be used as source for creating / transforming between them.
I think we can ensure non-emptiness by using specific constructors:
- We can create from a single value, alternatively taking an additional normal
seq
as “tail”. - We can define a closed range operator that return a
NonEmptySeq
|..
, also..|
and|..|
where the number besides the bar always exists in the range. Example1|..3 -> NonEmptySeq [1;2;3]
,1|..0 -> NonEmptySeq [1]
,10|..|3 -> NonEmptySeq [3]
. - As in NonEmptyList, we can define a builder that doesn’t allow the Zero method, for NonEmptySeq literals:
nes {1;2;3}
- Finally, we can add some safe/unsafe constructors from regular sequences, by checking on
Seq.isEmpty
Any thoughs?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Count of non-empty sequences of a String
Given a string s, the task is to find the number of possible non-empty sequences of letters that can be made. To check...
Read more >NonEmptySeq
A data type which represents a Seq guaranteed to contain at least one element. Note that the constructor is private to prevent accidental...
Read more >clojure - Why prefer seq over non-empty as a predicate?
1 Answer. Surprise, it uses seq as the test of non-emptiness too. This not-empty is useful if the type matters -- nth performance...
Read more >Data.Sequence.NonEmpty
Non-Empty Finite Sequences. | An NESeq a is a non-empty (but finite) sequence of values of type a . Generally has the same...
Read more >Scala Tutorial - NonEmpty Function Example
In this Scala beginner tutorial, you will learn how to use the nonempty function with example to test whether a collection is not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Good point, then we don’t.
What do you mean with
From the above list, only in the case of a unsafe constructor we’ll be assuming.
Regarding your question:
We would simply follow the same rules as the
..
operator, I mean require the same static members.