module Enumerable(T)
Overview
Gather, check and annotate types registering a format
Direct including types
Defined in:
chem/core_ext/enumerable.crchem/register_format.cr
Instance Method Summary
-
#===(atom : Chem::Atom) : Bool
Case equality.
-
#===(chain : Chem::Chain) : Bool
Case equality.
-
#===(residue : Chem::Residue) : Bool
Case equality.
-
#average(weights : Indexable(Number))
Returns the weighted average of the elements in the collection.
-
#average(weights : Indexable(Number), & : T -> _)
Returns the weighted average of the results of the passed block for each element in the collection.
-
#find(pattern, if_none default = nil)
Returns the first element in the collection for which
pattern === element. -
#find!(pattern)
Returns the first element in the collection for which
pattern === element. -
#mean
Returns the arithmetic mean of the elements in the collection.
-
#mean(& : T -> _)
Returns the arithmetic mean of the results of the passed block for each element in the collection.
- #to_dcd(io : IO, title : String | Nil = nil) : Nil
- #to_dcd(title : String | Nil = nil) : String
- #to_dcd(path : Path | String, title : String | Nil = nil) : Nil
- #to_mol2(io : IO) : Nil
- #to_mol2(path : Path | String) : Nil
- #to_mol2 : String
- #to_pdb(io : IO, conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : Nil
- #to_pdb(conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : String
- #to_pdb(path : Path | String, conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : Nil
- #to_sdf(io : IO, variant : Mol::Variant = :v2000) : Nil
- #to_sdf(path : Path | String, variant : Mol::Variant = :v2000) : Nil
- #to_sdf(variant : Mol::Variant = :v2000) : String
- #to_xyz(io : IO, extended : Bool = false, fields : Array(String) = [] of String) : Nil
- #to_xyz(extended : Bool = false, fields : Array(String) = [] of String) : String
- #to_xyz(path : Path | String, extended : Bool = false, fields : Array(String) = [] of String) : Nil
Instance Method Detail
Returns the weighted average of the elements in the collection.
Raises EmptyError if the collection is empty or ArgumentError if
weights has a different number of elements.
Expects all element types to respond to #+ and #/ methods.
[1, 2, 3, 4, 5, 6].average((1..6).to_a) # => 4.333333333333333
(1..6).average((1..6).to_a) # => 4.333333333333333
([] of Int32).average([1, 1, 1]) # raises EmptyError
(1..6).average([1, 1]) # raises ArgumentError
NOTE This method calls .additive_identity on the element type and
weights' element type to determine the type of the intermediate
sum values.
Returns the weighted average of the results of the passed block for
each element in the collection. Raises EmptyError if the
collection is empty or ArgumentError if weights has a different
number of elements.
Expects all element types to respond to #+ and #/ methods.
["Alice", "Bob"].average([7, 2], &.size) # => 4.555555555555555
('a'..'z').average((0..25).to_a, &.ord) # => 4.333333333333333
([] of String).average([1, 1], &.size) # raises EmptyError
["Alice", "Bob"].average([1, 1, 1], &.size) # raises ArgumentError
NOTE This method calls .additive_identity on the yielded type and
weights' element type to determine the type of the intermediate
sum values.
Returns the first element in the collection for which pattern === element.
[1, 3, 2, 5, 4, 6].find(3..5) # => 3
["Alice", "Bob"].find(/^A/) # => "Alice"
[1, 2, 3, 4].find(8..) # => nil
Returns the first element in the collection for which pattern === element.
[1, 3, 2, 5, 4, 6].find!(3..5) # => 3
["Alice", "Bob"].find!(/^A/) # => "Alice"
[1, 2, 3, 4].find(8..) # raises Enumerable::NotFoundError
Returns the arithmetic mean of the elements in the collection.
Raises EmptyError if the collection is empty.
Expects all element types to respond to #+ and #/ methods.
[1, 2, 3, 4, 5, 6].mean # => 3.5
(1..6).mean # => 3.5
([] of Int32).mean # raises EmptyError
NOTE This method calls .additive_identity on the element type to
determine the type of the intermediate sum.
Returns the arithmetic mean of the results of the passed block for
each element in the collection. Raises EmptyError if the
collection is empty.
Expects all element types to respond to #+ and #/ methods.
["Alice", "Bob"].mean(&.size) # => 4
('a'..'z').mean(&.ord) # => 109.5
([] of String).mean(&.size) # raises EmptyError
NOTE This method calls .additive_identity on the yielded type to
determine the type of the intermediate sum.