package reason-standard
Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
Comparator provide a way for custom data structures to be used with Map
s and Set
s
Say we have a module Book
which we want to be able to create a Set
of
module Book = struct
type t = {
isbn: string;
title: string;
}
end
First we need to make our module conform to the S
signature.
This can be done by using the make
function or the Make
functor.
module Book = struct
type t = {
isbn: string;
title: string;
}
module ByIsbn = (
val Comparator.make ~compare:(fun bookA bookB ->
String.compare bookA.isbn bookb.isbn
)
)
end
Then we can create a Set
Set.ofList (module Book.ByIsbn) [
{ isbn="9788460767923"; title="Moby Dick or The Whale" }
]
A type alias that is useful typing functions which accept first class modules like Map.empty
or Set.ofArray
Create a new comparator by providing a compare function.
Examples
module Book = struct
type t = {
isbn: string;
title: string;
}
module ByTitle = (
val Comparator.make ~compare:(fun bookA bookB ->
String.compare bookA.title bookb.title)
)
end
let books = Set.empty (module Book.ByTitle)
module Make (Comparable : T) : S with type t := Comparable.t
Create a new comparator by providing a module which satisifies T
.
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>