Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testable for seq and contramap (for testable) #412

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

xvw
Copy link
Contributor

@xvw xvw commented Sep 5, 2024

This PR adds:

  • seq (to produces 'a Seq.t testable) Because the Seq.t type has become very common in the standard library
  • contramap which allows you to go from an 'a testable to a 'b testable giving a function from b -> 'a (because a testable is a contravariant functor). I have often found the function useful for implementing testables quickly when there is a trivial transformation.

@@ -107,6 +110,10 @@ val neg : 'a testable -> 'a testable
(** [neg t] is [t]'s negation: it is [true] when [t] is [false] and it is
[false] when [t] is [true]. *)

val contramap : ('b -> 'a) -> 'a testable -> 'b testable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind naming this map -- even if it doesn't follow the theory, that's what more users would expect :p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about keeping the Fmt convention by calling it using? (Because I find that calling it map makes reading its signature ... complicated).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, btw you are right, map works well, fixed on 415abb4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using could work too - no strong opinion between map and using

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I go for map :)

@samoht
Copy link
Member

samoht commented Sep 23, 2024

Thanks that looks like a great addition!

LGTM apart questions on names (the most difficult questions, as usual)

Copy link
Collaborator

@MisterDA MisterDA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seq.uncons was introduced in OCaml 4.14. We may want to keep supporting OCaml 4.08 for a while still.

src/alcotest-engine/test.ml Show resolved Hide resolved
@MisterDA MisterDA merged commit 8d30762 into mirage:main Sep 23, 2024
12 checks passed
@xvw xvw deleted the contramap-for-testable branch September 23, 2024 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants