1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! A small collection of traits for implementing higher order functions.
//!
//! # Init:
//!
//! ```rust
//! use higher_order_functions::Init;
//!
//! struct House { number: usize }
//!
//! // [T; N]: Init<T, usize>
//! let road = <[House; 3]>::init(|i| House { number: i + 1 });
//!
//! assert_eq!(road[0].number, 1);
//! assert_eq!(road[1].number, 2);
//! assert_eq!(road[2].number, 3);
//! ```
//!
//! # Map:
//!
//! ```rust
//! use higher_order_functions::Map;
//!
//! let arr = [1, 4, 6, -3, 6].map(|x| x * 2);
//!
//! assert_eq!(arr, [2, 8, 12, -6, 12]);
//! ```
//!
//! ```rust
//! use higher_order_functions::Map;
//!
//! let arr = [1, 4, 6, -3, 6].map(f64::from);
//!
//! assert_eq!(arr, [1.0, 4.0, 6.0, -3.0, 6.0]);
//! ```
//!
//! # Zip:
//!
//! ```rust
//! use higher_order_functions::Zip;
//!
//! let a = [1, 2, 3];
//! let b = ["a", "b", "c"];
//!
//! let arr = a.zip(b, |ax, bx| (ax, bx));
//!
//! assert_eq!(arr, [(1, "a"), (2, "b"), (3, "c")]);
//! ```
//!
//! ```rust
//! use higher_order_functions::Zip;
//!
//! let a = [1, 2, 3];
//! let b = [4, 5, 6];
//!
//! let arr = a.zip(b, |ax, bx| ax * bx);
//!
//! assert_eq!(arr, [4, 10, 18]);
//! ```
//!
//! # Section:
//!
//! ```rust
//! use higher_order_functions::Section;
//!
//! let a: [u32; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
//!
//! let arr: [u32; 4] = a.section(3); // Extracts 4 elements starting at a[3]
//!
//! assert_eq!(arr, [4, 5, 6, 7]);
//! ```
//!
//! To use this, add it as a dependency to your Cargo.toml:
//! ```toml
//! [dependencies]
//! higher_order_functions = "^0.1.1"
//! ```

#![no_std]

#![feature(const_generics)]
#![feature(generic_associated_types)]
#![feature(external_doc)]
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_extra)]

#![doc(html_root_url = "https://docs.rs/higher_order_functions/0.1.1")]

#[cfg(feature = "std")]
extern crate std as lib;

#[cfg(all(not(feature = "std"), feature = "alloc"))]
extern crate alloc as lib;

mod helpers;
mod init;
mod map;
mod zip;
mod section;

pub use {
	init::{
		Init,
	},
	map::{
		Map,
	},
	zip::{
		Zip,
	},
	section::{
		Section,
	},
};

// Include the readme and changelog as hidden documentation so they're tested by cargo test
#[doc(include = "../README.md")]
#[doc(include = "../CHANGELOG.md")]
type _Doctest = ();