simplify `from_elem` and add `from_fn`