package core_kernel

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Reversed_listSource

Sourcetype 'a t =
  1. | []
  2. | :: of 'a * 'a t

Reversed_list is constructed the same way as a list, but it needs to be reversed before it can be used. This is helpful when building up a list in reverse order to force reversal before use.

include Ppx_compare_lib.Equal.S1 with type 'a t := 'a t
Sourceval equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

The API of Reversed_list is purposely minimal to encourage destructing the list near the point of construction. Callers that are motivated to extend this API to avoid the overhead of reversal may be better off using a queue.

Sourceval of_list_rev : 'a list -> 'a t

of_list_rev reverses the input list.

Sourceval rev : 'a t -> 'a list
Sourceval rev_append : 'a t -> 'a list -> 'a list
Sourceval rev_map : 'a t -> f:('a -> 'b) -> 'b list
Sourceval rev_filter_map : 'a t -> f:('a -> 'b option) -> 'b list
Sourceval is_empty : 'a t -> bool
Sourceval length : 'a t -> int
Sourcemodule With_sexp_of : sig ... end

Renders sexps without reversing the list. E.g. 1::2 is represented as (1 2). of_sexp and other derivations are not supported because Reversed_list is meant to be a more ephemeral type and of_sexp is only provided for printing convenience, e.g., for expect tests. Callers that are motivated to add derivations because they want to use Reversed_list as part of a type may be better off defining a custom type with a more meaningful name that conveys what the ordering represents instead of a generic "reversed list."

Sourcemodule With_rev_sexp_of : sig ... end

Renders sexps after reversing the list. E.g. 1::2 is represented as (2 1). See With_sexp_of for why only sexp_of is provided.