question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Given 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. Example 1|..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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
gustycommented, Sep 16, 2020

Good point, then we don’t.

1reaction
gustycommented, Sep 11, 2020

What do you mean with

In many instances we assume that the sequence has 1

From the above list, only in the case of a unsafe constructor we’ll be assuming.

Regarding your question:

Then there is the question about other types that has some sort of sequenceable or range behaviour?

We would simply follow the same rules as the .. operator, I mean require the same static members.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found